Compare commits

..

5 Commits

Author SHA1 Message Date
35eb89c494 completed day 4 2025-12-04 00:38:21 -05:00
b175cf9812 completed day four part 1 2025-12-04 00:31:51 -05:00
1487a1cd27 utility Coordinate.cs 2025-12-04 00:31:43 -05:00
31780b1dca prepping Day 4 2025-12-04 00:14:16 -05:00
1cce184e86 part two completed somehow 2025-12-04 00:13:01 -05:00
5 changed files with 120 additions and 7 deletions

View File

@@ -24,6 +24,10 @@
<Content Include="Input\DayThree.txt"> <Content Include="Input\DayThree.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<None Remove="Input\DayFour.txt" />
<Content Include="Input\DayFour.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,10 +8,13 @@ public class Lobby : IAdventSolution
public AdventSolution Solve(string input) public AdventSolution Solve(string input)
{ {
var lines = input.SplitLines(); var lines = input.SplitLines();
var total = 0; var total = 0UL;
var total2 = 0UL;
foreach (var line in lines) foreach (var line in lines)
{ {
var first = '0'; total += GreatestXDigits(line, 2);
total2 += GreatestXDigits(line, 12);
/*var first = '0';
var second = '0'; var second = '0';
for (var i = 0; i < line.Length; i++) for (var i = 0; i < line.Length; i++)
{ {
@@ -25,11 +28,41 @@ public class Lobby : IAdventSolution
second = line[i]; second = line[i];
} }
} }
total += int.Parse($"{first}{second}");*/
total += int.Parse($"{first}{second}");
} }
return new AdventSolution(total.ToString(), null); return new AdventSolution(total.ToString(), total2.ToString());
}
private readonly List<char> _chars = new();
private ulong GreatestXDigits(string input, int digits)
{
_chars.Clear();
_chars.Add(input[0]);
for (var i = 1; i < input.Length; i++)
{
var remainingChars = input.Length - i - 1;
var c = input[i];
if(!IsReplace(c, remainingChars, digits) && _chars.Count < digits)
{
_chars.Add(c);
}
}
return ulong.Parse(string.Join("", _chars));
}
private bool IsReplace(char c, int remaining, int digits)
{
for (var i = 0; i < _chars.Count; i++)
{
if (c <= _chars[i] || (remaining < digits - (i+1))) continue;
_chars.RemoveRange(i, _chars.Count - i);
_chars.Add(c);
return true;
}
return false;
} }
} }

View File

@@ -0,0 +1,57 @@
using AdventOfCode2025.Utils;
namespace AdventOfCode2025;
public class PrintingDepartment : IAdventSolution
{
private readonly HashSet<Coordinate> _existingRolls = new();
public AdventSolution Solve(string input)
{
var map = input.SplitLines();
for (var i = 0; i < map.Length; i++)
{
for (var j = 0; j < map[i].Length; j++)
{
if(map[i][j] != '.')
_existingRolls.Add(new Coordinate(j, i));
}
}
var initialCount = _existingRolls.Count;
var accessible = -1;
var firstAccessible = -1;
var toRemove = new HashSet<Coordinate>();
while(accessible != 0 && _existingRolls.Count > 0)
{
accessible = 0;
foreach (var c in _existingRolls)
{
if (!IsAccessible(c)) continue;
accessible++;
toRemove.Add(c);
}
if (firstAccessible == -1) firstAccessible = accessible;
_existingRolls.RemoveWhere(x => toRemove.Contains(x));
toRemove.Clear();
}
return new AdventSolution(firstAccessible.ToString(), (initialCount - _existingRolls.Count).ToString());
}
private readonly Coordinate[] _directions =
[
new(-1, -1), new( 0, -1), new( 1, -1),
new(-1, 0), new( 1, 0),
new(-1, 1), new( 0, 1), new( 1, 1)
];
private bool IsAccessible(Coordinate position)
{
var neighbors = 0;
foreach (var dir in _directions)
{
if(_existingRolls.Contains(position + dir)) neighbors++;
}
return neighbors < 4;
}
}

View File

@@ -10,3 +10,6 @@ AdventSolver<GiftShop>.Solve(dayTwoInput, 2, "Gift Shop");
var dayThreeInput = await File.ReadAllTextAsync("./Input/DayThree.txt"); var dayThreeInput = await File.ReadAllTextAsync("./Input/DayThree.txt");
AdventSolver<Lobby>.Solve(dayThreeInput, 3, "Lobby"); AdventSolver<Lobby>.Solve(dayThreeInput, 3, "Lobby");
var dayFourInput = await File.ReadAllTextAsync("./Input/DayFour.txt");
AdventSolver<PrintingDepartment>.Solve(dayFourInput, 4, "Printing Department");

View File

@@ -0,0 +1,16 @@
using System.Numerics;
namespace AdventOfCode2025.Utils;
public record struct Coordinate(int X, int Y) : IAdditionOperators<Coordinate,Coordinate,Coordinate>, ISubtractionOperators<Coordinate,Coordinate,Coordinate>
{
public static Coordinate operator +(Coordinate left, Coordinate right)
{
return new Coordinate(left.X + right.X, left.Y + right.Y);
}
public static Coordinate operator -(Coordinate left, Coordinate right)
{
return new Coordinate(left.X - right.X, left.Y - right.Y);
}
}