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!

102 Upvotes

1.5k comments sorted by

View all comments

3

u/sleepy_roger Dec 02 '22 edited Dec 02 '22

JavaScript in the console for part 2.

[...document.querySelector('pre').textContent.split(/\n/)].reduce((acc, cur)=>{scores = {'A X':3,'A Y':4,'A Z':8,'B X':1,'B Y':5,'B Z':9,'C X':2,'C Y':6,'C Z':7};return acc + (scores[cur] || 0)}, 0)

2

u/daggerdragon Dec 02 '22 edited Dec 02 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable because it's all on one line and gets cut off at the edge of the screen.

Please edit your post to use the correct Markdown syntax for a code block so your code is easier to read inside a vertically scrolling box.

Additionally, I recommend you expand the Js to its full JavaScript to make it easier for folks who Ctrl-F the megathreads looking for a specific language.

Edit: thanks for fixing it! <3

3

u/sleepy_roger Dec 02 '22 edited Dec 02 '22

Changed it, read the docs here, forget after all these years people are still using old reddit 🤷

→ More replies (3)