Extract Coordinate, IntegerRange and Coordinate3d to new AdventOfCode.HelperClasses project and refactor solution for modularity and type consistency

This commit is contained in:
Sebastian Lindemeier committed 2025-12-12 13:14:17 +01:00
1 parent 85516cd783
commit aaf32260d0
13 files changed
+119 -143

No files matched your search

@@ -0,0 +1,28 @@
namespace AdventOfCode.HelperClasses;
public record IntegerRange(long start, long end)
{
public long Count() => end - start + 1;
public bool Contains(long number) => start <= number && end >= number;
public bool TryCombine(IntegerRange other, out IntegerRange combined)
{
if (Contains(other.start))
{
var isEndInRange = Contains(other.end);
combined = isEndInRange ? this : this with {end = other.end};
return true;
}
if (other.Contains(start))
{
var isEndInRange = other.Contains(end);
combined = isEndInRange ? other : other with {end = end};
return true;
}
combined = this;
return false;
}
}