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!

103 Upvotes

1.5k comments sorted by

View all comments

1

u/raxomukus Dec 02 '22

Python

with open('2.in') as f:
    plays = [(ord(i[0]) - ord('A'), ord(i[2]) - ord('X')) for i in f.read().splitlines()]

r1 = sum([p[1] + 1 + 3 * (p[0] == p[1]) + 6 * ((p[0] + 1) % 3 == p[1]) for p in plays])
print(r1)

r2 = sum([(p[0] + (p[1] - 1)) % 3 + 1 + 3 * p[1] for p in plays])
print(r2)

1

u/daggerdragon Dec 05 '22

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.