Syldarion

AdventOfCode'22-Day2

Dec 2nd, 2022
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. # A & X -> ROCK
  2. # B & Y -> PAPER
  3. # C & Z -> SCISSORS
  4. # Using rock = 1
  5. # Using paper = 2
  6. # Using scissors = 3
  7. # Losing = 0
  8. # Drawing = 3
  9. # Winning = 6
  10.  
  11. MATCH_VALUES = {
  12. "A X": 4, # Rock + Rock
  13. "A Y": 8, # Rock + Paper
  14. "A Z": 3, # Rock + Scissors
  15. "B X": 1, # Paper + Rock
  16. "B Y": 5, # Paper + Paper
  17. "B Z": 9, # Paper + Scissors
  18. "C X": 7, # Scissors + Rock
  19. "C Y": 2, # Scissors + Paper
  20. "C Z": 6 # Scissors + Scissors
  21. }
  22.  
  23. # X -> lose the round
  24. # Y -> draw the round
  25. # Z -> win the round
  26. RESULT_VALUES = {
  27. "A X": 3, # Rock + Scissors
  28. "A Y": 4, # Rock + Rock
  29. "A Z": 8, # Rock + Paper
  30. "B X": 1, # Paper + Rock
  31. "B Y": 5, # Paper + Paper
  32. "B Z": 9, # Paper + Scissors
  33. "C X": 2, # Scissors + Paper
  34. "C Y": 6, # Scissors + Scissors
  35. "C Z": 7 # Scissors + Rock
  36. }
  37.  
  38.  
  39. def part01(*args):
  40. file_path = args[0]
  41. with open(file_path, "r") as f:
  42. rounds = f.readlines()
  43. guide_sum = sum([MATCH_VALUES[x.strip()] for x in rounds])
  44. return guide_sum
  45.  
  46.  
  47. def part02(*args):
  48. file_path = args[0]
  49. with open(file_path, "r") as f:
  50. rounds = f.readlines()
  51. guide_sum = sum([RESULT_VALUES[x.strip()] for x in rounds])
  52. return guide_sum
  53.  
Advertisement
Add Comment
Please, Sign In to add comment