Range.cs 804 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. namespace Day19;
  2. public record Range(int Start, int End)
  3. {
  4. public static Range Empty = new Range(-1, -1);
  5. public long Size => this == Empty ? 0 : (End - Start + 1);
  6. public Range LessThan(int value)
  7. {
  8. if (value <= Start)
  9. {
  10. return Empty;
  11. }
  12. if (value > End)
  13. {
  14. return this;
  15. }
  16. return this with { End = value - 1 };
  17. }
  18. public Range GreaterThan(int value)
  19. {
  20. if (value >= End)
  21. {
  22. return Empty;
  23. }
  24. if (value < Start)
  25. {
  26. return this;
  27. }
  28. return this with { Start = value + 1 };
  29. }
  30. public override string ToString()
  31. {
  32. return $"{Start} - {End}";
  33. }
  34. }