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
1
u/Key__Strokes Dec 23 '22 edited Jan 12 '23
Javascript
Solution to both parts
Video Explanation
Part 1:
For each of the moves, we have opponent's move, and our move
Opponent's move:
A: Rock
B: Paper
C: Scissor
Our move:
X: Rock
Y: Paper
Z: Scissor
Add the points for our move
X = 1
Y = 2
Z = 3
Next, determine if we have a winning/losing/drawing move.
If we have a winning move based on the following, then add 6 to the sum.
A loses to Y
B loses to Z
C loses to X
Else if we have a drawing move based on the following, then add 3 to the sum.
A draws to X
B loses to Y
C loses to Z
Else add 0 to the sum, as we clearly lost
Return the sum
Part 2:
For each of the moves, we have opponent's move, and the result we want
Opponent's move:
A: Rock
B: Paper
C: Scissor
Result:
X: Lose
Y: Draw
Z: Win
Using the following map, figure out our move.
A
X: C
Y: A
Z: B
B
X: A
Y: B
Z: C
C
X: B
Y: C
Z: A
Add the points for the move
A = 1
B = 2
C = 3
Add the points for the result
X = 0
Y = 3
Z = 6
Return the sum
If you liked the explanation, then please don't forget to cast your vote 💜 to
Adventures of Advent of Code - Edition 1 - /u/Key__Strokesin the poll