-
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
08aa3ee
commit 3905834
Showing
3 changed files
with
89 additions
and
0 deletions.
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,54 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace AdventOfCode | ||
{ | ||
/// <summary> | ||
/// Solver for Day 25 | ||
/// </summary> | ||
public class Day25 | ||
{ | ||
public int Part1(string input) | ||
{ | ||
List<Schematic> locks = []; | ||
List<Schematic> keys = []; | ||
|
||
foreach (string chunk in input.TrimEnd().Split("\n\n")) | ||
{ | ||
string[] lines = chunk.Split("\n"); | ||
|
||
bool isLock = lines[0] == "#####"; | ||
|
||
IEnumerable<string> rows = isLock ? lines.Skip(1) : lines.Reverse().Skip(1); | ||
|
||
int height0 = 0, height1 = 0, height2 = 0, height3 = 0, height4 = 0; | ||
|
||
foreach (string row in rows) | ||
{ | ||
height0 += row[0] == '#' ? 1 : 0; | ||
height1 += row[1] == '#' ? 1 : 0; | ||
height2 += row[2] == '#' ? 1 : 0; | ||
height3 += row[3] == '#' ? 1 : 0; | ||
height4 += row[4] == '#' ? 1 : 0; | ||
} | ||
|
||
if (isLock) | ||
{ | ||
locks.Add(new Schematic(height0, height1, height2, height3, height4)); | ||
} | ||
else | ||
{ | ||
keys.Add(new Schematic(height0, height1, height2, height3, height4)); | ||
} | ||
} | ||
|
||
return keys.Sum(k => locks.Count(l => k.Height0 + l.Height0 < 6 | ||
&& k.Height1 + l.Height1 < 6 | ||
&& k.Height2 + l.Height2 < 6 | ||
&& k.Height3 + l.Height3 < 6 | ||
&& k.Height4 + l.Height4 < 6)); | ||
} | ||
|
||
private record Schematic(int Height0, int Height1, int Height2, int Height3, int Height4); | ||
} | ||
} |
Binary file not shown.
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,35 @@ | ||
using System.IO; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace AdventOfCode.Tests | ||
{ | ||
public class Day25Tests | ||
{ | ||
private readonly ITestOutputHelper output; | ||
private readonly Day25 solver; | ||
|
||
public Day25Tests(ITestOutputHelper output) | ||
{ | ||
this.output = output; | ||
this.solver = new Day25(); | ||
} | ||
|
||
private static string GetRealInput() | ||
{ | ||
string input = File.ReadAllText("inputs/day25.txt"); | ||
return input; | ||
} | ||
|
||
[Fact] | ||
public void Part1_RealInput_ProducesCorrectResponse() | ||
{ | ||
var expected = 3021; | ||
|
||
var result = solver.Part1(GetRealInput()); | ||
output.WriteLine($"Day 25 - Part 1 - {result}"); | ||
|
||
Assert.Equal(expected, result); | ||
} | ||
} | ||
} |