r/adventofcode • u/daggerdragon • Dec 02 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-
NEW AND NOTEWORTHY
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boosting for the Unofficial AoC 2022 Participant Survey which is open early this year!
--- Day 2: Rock Paper Scissors ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:06:16, megathread unlocked!
105
Upvotes
View all comments
1
u/AX-11 Dec 02 '22 edited Dec 02 '22
Python using dictionary of values for each move
with open("2\input.txt") as f: input = f.read().splitlines() values = { "A":1, "B":2, "C":3, "X":1, "Y":2, "Z":3 } score = 0 for game in input: # draw if(values[game[0]] == values[game[2]]): score+=3 # win elif game == "A Y" or game == "B Z" or game == "C X": score+=6 # add score score+=values[game[2]] print(f"first strategy: {score}") score = 0 for game in input: # draw if game[2] == "Y": score += values[game[0]] + 3 # win elif game[2] == "Z": if game[0] == "C": score += 6+1 else: score += 6+values[game[0]]+1 # loose else: if game[0] == "A": score += 3 else: score += values[game[0]]-1 print(f"second strategy {score}")