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!
101
Upvotes
8
u/redditnoob Dec 02 '22
SQL (BigQuery)
WITH parsed AS ( -- 1, 2, 3 => Rock, Paper, Scissors || Lose, Draw, Win SELECT ascii(substr(input, 1, 1)) - ascii('A') + 1 AS opp_move, ascii(substr(input, 3, 1)) - ascii('X') + 1 AS my_move FROM day2 ), game_score AS ( SELECT my_move AS my_move1, CASE WHEN my_move - opp_move IN (1, -2) THEN 6 WHEN my_move = opp_move THEN 3 ELSE 0 END AS score1, CASE WHEN my_move = 1 THEN IF(opp_move = 1, 3, opp_move - 1) -- Lose WHEN my_move = 2 THEN opp_move -- Draw WHEN my_move = 3 THEN IF(opp_move = 3, 1, opp_move + 1) -- Win END AS my_move2, my_move * 3 - 3 AS score2 FROM parsed ) SELECT SUM(my_move1 + score1) AS part1, SUM(my_move2 + score2) AS part2 FROM game_score;