-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76e0a21
commit 3a3fbd3
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../inputs/2024/day25/input |
Submodule inputs
updated
from e5ee35 to 32d82f