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; } }