Compare commits

..

2 Commits

Author SHA1 Message Date
1ac8cee3d5 day two part two 2025-12-02 10:39:54 -05:00
8dbf5946ee day two part one 2025-12-02 10:31:01 -05:00
3 changed files with 56 additions and 1 deletions

View File

@@ -16,6 +16,10 @@
<Content Include="Input\Test.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="Input\DayTwo.txt" />
<Content Include="Input\DayTwo.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,48 @@
using System.Text.RegularExpressions;
namespace AdventOfCode2025;
public class GiftShop : IAdventSolution
{
private readonly Regex _regex = new(@"^(.+)\1+$");
public AdventSolution Solve(string input)
{
var ranges = input.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
ulong totalInvalid = 0;
ulong newInvalid = 0;
foreach (var rangeString in ranges)
{
var range = GetRange(rangeString);
for (var i = range.Min; i <= range.Max; i++)
{
if (IsInvalid(i))
totalInvalid += i;
if(IsRepeat(i))
newInvalid += i;
}
}
return new AdventSolution(totalInvalid.ToString(),newInvalid.ToString());
}
private bool IsInvalid(ulong id)
{
var s = id.ToString();
var half = s.Length / 2;
var first = s[..half];
var second = s[half..];
return first == second;
}
private bool IsRepeat(ulong id) => _regex.IsMatch(id.ToString());
private Range GetRange(string input)
{
var numbers = input.Split('-', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
return new Range(ulong.Parse(numbers[0]), ulong.Parse(numbers[^1]));
}
}
public record struct Range(ulong Min, ulong Max);

View File

@@ -3,4 +3,7 @@
Console.WriteLine("Advent of Code 2025");
var dayOneInput = await File.ReadAllTextAsync("./Input/DayOne.txt");
AdventSolver<SecretEntrance>.Solve(dayOneInput, 1, "Secret Entrance");
AdventSolver<SecretEntrance>.Solve(dayOneInput, 1, "Secret Entrance");
var dayTwoInput = await File.ReadAllTextAsync("./Input/DayTwo.txt");
AdventSolver<GiftShop>.Solve(dayTwoInput, 2, "Gift Shop");