Extract Coordinate, IntegerRange and Coordinate3d to new AdventOfCode.HelperClasses project and refactor solution for modularity and type consistency
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user