Skip to content

Instantly share code, notes, and snippets.

@dnnsmnstrr
Last active December 2, 2022 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnsmnstrr/ac7d9df1a2165a829b86e39680b91ece to your computer and use it in GitHub Desktop.
Save dnnsmnstrr/ac7d9df1a2165a829b86e39680b91ece to your computer and use it in GitHub Desktop.
Advent of Code 2022
const input = `
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
`
const values = input.split('\n\n').map(values => values.split('\n').filter(value => !!value)) //?
const summedValues = values.map(values => values.reduce((sum, value) => sum + parseInt(value), 0)) //?
const sortedValues = summedValues.sort((a, b) => b - a)
const largestValue = sortedValues.slice(0, 1)
console.log('Calories of top elf', largestValue)
const top3 = sortedValues.slice(0, 3)
const top3sum = top3.reduce((sum, value) => sum + value, 0)
console.log('Top 3 elves total calories', top3sum)
const exampleInput = `
A Y
B X
C Z
`
// A = rock
// B = paper
// C = scissors
// Round 1
// Y = paper - 2
// X = rock - 1
// Z = scissors - 3
// Round 2
// X = lose - 0
// Y = draw - 3
// Z = win - 6
const scoreMap1 = {
'A Y': 8,
'B X': 1,
'C Z': 6,
'A Z': 3,
'B Y': 5,
'C X': 7,
'A X': 4,
'B Z': 9,
'C Y': 2,
}
const scoreMap2 = {
'A Y': 4,
'B X': 1,
'C Z': 7,
'A Z': 8,
'B Y': 5,
'C X': 2,
'A X': 3,
'B Z': 9,
'C Y': 6,
}
const rounds = exampleInput.split('\n').filter(Boolean) // ?
const scores1 = rounds.map((round) => scoreMap1[round]) // ?
const scores2 = rounds.map((round) => scoreMap2[round]) // ?
const totalScore1 = scores1.reduce((acc, score) => acc + score, 0) // ?
const totalScore2 = scores2.reduce((acc, score) => acc + score, 0) // ?
console.log('Total Score - Round 1:', totalScore1)
console.log('Total Score - Round 2:', totalScore2)
@dnnsmnstrr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment