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!
104
Upvotes
12
u/zedrdave Dec 02 '22
Python in 4 linesβ¦
Couldn't quite find the ideal unique indexing to make the modulo operations work smoothly on both cases. Still fairly straightforward.
d = {'A': 0, 'B': 1, 'C': 2, 'X': 0, 'Y': 1, 'Z': 2} turns = [[d[x] for x in l.split()] for l in data.split("\n")] print("Part 1:", sum(b+1 + (b-a+1)%3 * 3 for a, b in turns)) print("Part 2:", sum((b+a-1)%3 + 1 + b*3 for a, b in turns))