Data.cs 792 B

123456789101112131415161718192021222324252627282930313233
  1. namespace Day19;
  2. public record Data(IDictionary<string, Rule> Rules, IList<Part> Parts)
  3. {
  4. public int Process()
  5. {
  6. var sum = 0;
  7. foreach (var part in Parts)
  8. {
  9. Console.WriteLine(part);
  10. var next = "in";
  11. while (next != "A" && next != "R")
  12. {
  13. var rule = Rules[next];
  14. next = rule.Apply(part);
  15. }
  16. if (next == "A")
  17. {
  18. sum += part.Total;
  19. Console.WriteLine("ACCEPTED");
  20. Console.WriteLine();
  21. }
  22. else
  23. {
  24. Console.WriteLine("REJECTED");
  25. Console.WriteLine();
  26. }
  27. }
  28. return sum;
  29. }
  30. }