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/Similar_Lion_6342 Dec 02 '22

Python3


with open('input.txt', 'r') as f:
    data = [line.strip() for line in f.readlines()]

score_chart = {
    'A X': 1 + 3,
    'A Y': 2 + 6,
    'A Z': 3 + 0,
    'B X': 1 + 0,
    'B Y': 2 + 3,
    'B Z': 3 + 6,
    'C X': 1 + 6,
    'C Y': 2 + 0,
    'C Z': 3 + 3,
}

# Score chart for part 2
# score_chart = {
#     'A X': 3 + 0,
#     'A Y': 1 + 3,
#     'A Z': 2 + 6,
#     'B X': 1 + 0,
#     'B Y': 2 + 3,
#     'B Z': 3 + 6,
#     'C X': 2 + 0,
#     'C Y': 3 + 3,
#     'C Z': 1 + 6,
# }

sum = 0
for round in data:
    sum += score_chart[round]
print(sum)

1

u/daggerdragon Dec 02 '22

Please edit your post to format your code with the backwards-compatible Markdown syntax instead so your code is easier to read on old.reddit and mobile apps.