Part.cs 746 B

1234567891011121314151617181920212223242526272829303132
  1. namespace Day19;
  2. public class Part
  3. {
  4. private readonly IDictionary<string, int> _dict;
  5. public int X => _dict["x"];
  6. public int M => _dict["m"];
  7. public int S => _dict["s"];
  8. public int A => _dict["a"];
  9. public int Total => X + M + S + A;
  10. public Part(IDictionary<string, int> dict)
  11. {
  12. if (string.Join(string.Empty, dict.Keys.Order()) != "amsx")
  13. {
  14. throw new ArgumentException("Expected dictionary with keys amsx", nameof(dict));
  15. }
  16. _dict = dict;
  17. }
  18. public int Get(string property)
  19. {
  20. return _dict[property];
  21. }
  22. public override string ToString()
  23. {
  24. return $"x = {X}, m = {M}, a = {A}, s = {S}, ";
  25. }
  26. }