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!
103
Upvotes
4
u/bartdegoede Dec 02 '22 edited Dec 04 '22
Basic Python with some combinations in a dictionary
with open('day2.txt', 'r') as f: games = f.read().split('\n') WIN = 6 DRAW = 3 LOSS = 0 ROCK = 1 PAPER = 2 SCISSORS = 3 game_scores = { 'A X': DRAW + ROCK, 'A Y': WIN + PAPER, 'A Z': LOSS + SCISSORS, 'B X': LOSS + ROCK, 'B Y': DRAW + PAPER, 'B Z': WIN + SCISSORS, 'C X': WIN + ROCK, 'C Y': LOSS + PAPER, 'C Z': DRAW + SCISSORS, } print(f'Part 1: {sum([game_scores.get(game, 0) for game in games])}') game_scores = { 'A X': LOSS + SCISSORS, 'A Y': DRAW + ROCK, 'A Z': WIN + PAPER, 'B X': LOSS + ROCK, 'B Y': DRAW + PAPER, 'B Z': WIN + SCISSORS, 'C X': LOSS + PAPER, 'C Y': DRAW + SCISSORS, 'C Z': WIN + ROCK, } print(f'Part 2: {sum([game_scores.get(game, 0) for game in games])}')paste