| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- namespace Day19;
- public record Range(int Start, int End)
- {
- public static Range Empty = new Range(-1, -1);
- public long Size => this == Empty ? 0 : (End - Start + 1);
-
- public Range LessThan(int value)
- {
- if (value <= Start)
- {
- return Empty;
- }
- if (value > End)
- {
- return this;
- }
- return this with { End = value - 1 };
- }
- public Range GreaterThan(int value)
- {
- if (value >= End)
- {
- return Empty;
- }
- if (value < Start)
- {
- return this;
- }
- return this with { Start = value + 1 };
- }
-
- public override string ToString()
- {
- return $"{Start} - {End}";
- }
- }
|