Advent of Code 2022 https://adventofcode.com/2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

day2-1.py 783B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # https://adventofcode.com/2022/day/2
  2. MOVE_SCORES = {
  3. "A": 1,
  4. "B": 2,
  5. "C": 3,
  6. "X": 1,
  7. "Y": 2,
  8. "Z": 3
  9. }
  10. MOVE_BEATS = {
  11. "X": "C",
  12. "Y": "A",
  13. "Z": "B"
  14. }
  15. MOVE_EQUALS = {
  16. "X": "A",
  17. "Y": "B",
  18. "Z": "C"
  19. }
  20. def main():
  21. with open("input2.txt", "r") as file:
  22. moves = [line.strip() for line in file.readlines()]
  23. # moves = [(x, y) for line in inlines for x, y in line.split(" ")]
  24. scores = []
  25. for move in moves:
  26. (theirs, mine) = move.split(" ")
  27. cur_score = MOVE_SCORES[mine]
  28. if MOVE_BEATS[mine] == theirs:
  29. cur_score += 6
  30. elif MOVE_EQUALS[mine] == theirs:
  31. cur_score += 3
  32. scores.append(cur_score)
  33. print(sum(scores))
  34. if __name__ == "__main__":
  35. main()