Skip to content

Commit

Permalink
Add day25 (code chronicle)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-maxime committed Dec 25, 2024
1 parent 76e0a21 commit 3a3fbd3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
43 changes: 43 additions & 0 deletions 2024/day25/code-chronicle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
List<string[]> schematics = File.ReadAllText("input")
.Split("\n\n")
.Select(block => block.Split("\n", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
.ToList();

IEnumerable<int[]> GetSchematics(char type)
{
foreach (string[] schematic in schematics)
{
int[] lengths = new int[schematic[0].Length];
for (int x = 0; x < schematic[0].Length; x++)
{
int len = 0;
for (int y = 0; y < schematic.Length; y++)
{
if (schematic[y][x] == type) len += 1;
else break;
}
lengths[x] = len;
}
if (lengths[0] != 0)
{
yield return lengths;
}
}
}

List<int[]> locks = GetSchematics('#').ToList();
List<int[]> keys = GetSchematics('.').ToList();

int count = 0;
foreach (int[] lockPins in locks)
{
foreach (int[] keyPins in keys)
{
if (Enumerable.Range(0, lockPins.Length).All(i => lockPins[i] <= keyPins[i]))
{
count += 1;
}
}
}

Console.WriteLine(count);
10 changes: 10 additions & 0 deletions 2024/day25/day25.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions 2024/day25/input
2 changes: 1 addition & 1 deletion inputs

0 comments on commit 3a3fbd3

Please sign in to comment.