Extract IntArrayEqualityComparer to new AdventOfCode.HelperClasses project and refactor solution to use the shared class
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user