HiLo.cs 611 B

12345678910111213141516171819202122232425262728
  1. namespace Day20;
  2. public record HiLo(long High, long Low)
  3. {
  4. public static HiLo Zero { get; } = new HiLo(0L, 0L);
  5. public HiLo Add(HiLo other)
  6. {
  7. return new HiLo(High + other.High, Low + other.Low);
  8. }
  9. public HiLo Add(Pulse p)
  10. {
  11. return p.Value
  12. ? this with { High = High + 1 }
  13. : this with { Low = Low + 1 };
  14. }
  15. public HiLo Multiply(long factor)
  16. {
  17. return new HiLo(factor * High, factor * Low);
  18. }
  19. public override string ToString()
  20. {
  21. return $"High: {High} / Low: {Low}";
  22. }
  23. }