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!

103 Upvotes

1.5k comments sorted by

View all comments

2

u/samouri1 Dec 02 '22 edited Dec 05 '22

DevTools JavaScript:

const score1 = {  
  "A Z": 3, "B X": 1, "C Y": 2, // Losses  
  "A X": 4, "B Y": 5, "C Z": 6, // Ties  
  "A Y": 8, "B Z": 9, "C X": 7, // Wins  
};  
const score2 = {  
  "A Y": 4, "B X": 1, "C Z": 7, // Rock   
  "A Z": 8, "B Y": 5, "C X": 2, // Paper  
  "A X": 3, "B Z": 9, "C Y": 6, // Scissor  
};  
const answers = document.documentElement.innerText.trim()
  .split("\n")  
  .map((row) => [score1[row], score2[row]])  
  .reduce((acc, a) => [acc[0] + a[0], acc[1] + a[1]]);  
console.log(`Part 1: ${answers[0]}\nPart 2: ${answers[1]}`)
```

1

u/daggerdragon Dec 05 '22 edited Dec 05 '22

Please edit your post to expand the full name of the programming language (JavaScript). This makes it easier for folks to Ctrl-F the megathreads searching for solutions written in a specific programming language.

Edit: thanks for fixing it! <3

1

u/samouri1 Dec 05 '22

Thank you for letting me know! Done