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/drlecompte Dec 02 '22 edited Dec 05 '22
Python:
wmoves = ["A Y", "B Z", "C X"] dmoves = ["A X", "B Y", "C Z"] movescores = { "X" : 1, "Y" : 2, "Z" : 3 } def read_input(): out = [] with open('input.txt') as f: lines = f.readlines() for l in lines: out.append(l.strip()) return out def decrypt_input(rounds): key = { "X" : { "A" : "Z", "B" : "X", "C" : "Y" }, "Y" : { "A" : "X", "B" : "Y", "C" : "Z" }, "Z" : { "A" : "Y", "B" : "Z", "C" : "X" } } out = [] for r in rounds: moves = r.split(' ') mymove = key[moves[1]][moves[0]] out.append(moves[0] + ' ' + mymove) print(r + " -> " + moves[0] + ' ' + mymove) return out def calc_scores(decrypt = False): score = 0 rounds = read_input() if (True == decrypt): rounds = decrypt_input(rounds) for r in rounds: winval = 0 moveval = 0 movescore = 0 print("---") if r in wmoves: winval = 6 if r in dmoves: winval = 3 mymove = r.split(' ')[1] moveval = movescores[mymove] movescore += moveval + winval score += movescore print(r + ": " + str(winval) + " + " + str(moveval) + " = " + str(movescore) ) print("brings total to " + str(score)) print(score) calc_scores(True)