Extract IntArrayEqualityComparer to new AdventOfCode.HelperClasses project and refactor solution to use the shared class

This commit is contained in:
Sebastian Lindemeier
2025-12-12 12:39:31 +01:00
parent d0b612154a
commit 85516cd783
5 changed files with 42 additions and 32 deletions
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,24 @@
namespace AdventOfCode.HelperClasses;
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;
}
}