Extract IntArrayEqualityComparer to new AdventOfCode.HelperClasses project and refactor solution to use the shared class
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdvenOfCode.Contracts\AdvenOfCode.Contracts.csproj" />
|
||||
<ProjectReference Include="..\AdventOfCode.Extensions\AdventOfCode.Extensions.csproj" />
|
||||
<ProjectReference Include="..\AdventOfCode.HelperClasses\AdventOfCode.HelperClasses.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+2
-32
@@ -7,13 +7,14 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using AdvenOfCode.Contracts;
|
||||
using AdventOfCode.Extensions;
|
||||
using AdventOfCode.HelperClasses;
|
||||
using Microsoft.Z3;
|
||||
|
||||
namespace AoC_2025;
|
||||
|
||||
public class Day10 : IPuzzleSolver<long>
|
||||
{
|
||||
private (uint lamps, uint[] buttons, int[] joltages)[] ParsePuzzleInput(string path)
|
||||
private (uint lamps, uint[] buttons)[] ParsePuzzleInput(string path)
|
||||
{
|
||||
var puzzleInput = File.ReadAllLines(path)
|
||||
.Where(line => !string.IsNullOrWhiteSpace(line))
|
||||
@@ -41,16 +42,8 @@ public class Day10 : IPuzzleSolver<long>
|
||||
.Select(lampIndexes => lampIndexes.Aggregate((uint)0L, (acc, lampIndex) => acc | ((uint)1 << lampIndex)))
|
||||
.ToArray())
|
||||
.ToArray();
|
||||
var joltages = puzzleInput
|
||||
.Select(input => input.joltages)
|
||||
.Select(joltage => joltage
|
||||
.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(jolt => int.Parse(jolt))
|
||||
.ToArray())
|
||||
.ToArray();
|
||||
var res = lamps
|
||||
.Zip(buttons, (lamp, button) => (lamp, button))
|
||||
.Zip(joltages, (bl, joltage) => (bl.lamp, bl.button, joltage))
|
||||
.ToArray();
|
||||
return res;
|
||||
}
|
||||
@@ -272,27 +265,4 @@ public class Day10 : IPuzzleSolver<long>
|
||||
var answer = answerExpression is IntNum number ? number.Int64 : 0;
|
||||
return answer;
|
||||
}
|
||||
}
|
||||
|
||||
public class IntArrayEqualityComparer : IEqualityComparer<int[]>
|
||||
{
|
||||
public bool Equals(int[]? x, int[]? y)
|
||||
{
|
||||
if (x is null || y is null || x.Length != y.Length) return false;
|
||||
|
||||
return !x.Where((t, i) => t != y[i]).Any();
|
||||
}
|
||||
|
||||
public int GetHashCode(int[] obj)
|
||||
{
|
||||
var result = 17;
|
||||
foreach (var t in obj)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
result = result * 23 + t;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user