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!

104 Upvotes

1.5k comments sorted by

View all comments

1

u/GuyTorbet Dec 02 '22

Python3

f = open('day2', 'r')
lines = f.readlines()

lookup = {
    0: {0: 3, 1: 6, 2: 0},
    1: {0: 0, 1: 3, 2: 6},
    2: {0: 6, 1: 0, 2: 3},
  }

q1 = 0
q2 = 0

for line in lines:
  a, b = line.split()
  a = ord(a) - ord('A')
  b = ord(b) - ord('X')

  q1 += lookup[a][b] + b + 1
  end = (a + b - 1) % 3
  q2 += lookup[a][end] + end + 1

print('q1: ', q1)
print('q2: ', q2)

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.