r/adventofcode • • Dec 02 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-

NEW AND NOTEWORTHY


--- Day 2: Rock Paper Scissors ---


Post your code solution in this megathread.


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!

102 Upvotes

1.5k comments sorted by

View all comments

1

u/lxrsg Dec 02 '22

Python 3

lines = [x.strip().split(' ') for x in open('data.in').readlines()]
rps = dict(A=("Z", 1, "Y"), X=("C", 1, "B"), B=("X", 2, "Z"), Y=("A", 2, "C"), C=("Y", 3, "X"), Z=("B", 3, "A"))
print(sum(rps[u][1] if u == rps[t][0] else 6 + rps[u][1] if t == rps[u][0] else 3 + rps[u][1] for t, u in lines))
print(sum(rps[t][1] + 3 if u == 'Y' else rps[rps[t][0]][1] if u == 'X' else 6 + rps[rps[t][2]][1] for t, u in lines))

1

u/daggerdragon Dec 05 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable on old.reddit and many mobile clients; it's all on one line and gets cut off at the edge of the screen because it is not horizontally scrollable.

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box.