Notebooks 2.0 is here.

Public
Edited
Dec 7, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getPart1Solution()
Insert cell
function getPart1Solution () {
const scores = {
match: {
X: {A: 3, B: 0, C: 6},
Y: {A: 6, B: 3, C: 0},
Z: {A: 0, B: 6, C: 3}
},
bonus: {X: 1, Y: 2, Z: 3}
}

return input
// return document
// .querySelector('pre')
// .innerHTML
.trim()
.split('\n')
.map((token) => token.split(' '))
.map(([opponent, player]) => scores.match[player][opponent] + scores.bonus[player])
.reduce((total, score) => total + score, 0)
}
Insert cell
Insert cell
getPart2Solution()
Insert cell
function getPart2Solution () {
const scores = {
match: {
X: {A: 3, B: 0, C: 6},
Y: {A: 6, B: 3, C: 0},
Z: {A: 0, B: 6, C: 3}
},
bonus: {X: 1, Y: 2, Z: 3}
}

const choiceLookup = {
A: {X: 'Z', Y: 'X', Z: 'Y'},
B: {X: 'X', Y: 'Y', Z: 'Z'},
C: {X: 'Y', Y: 'Z', Z: 'X'}
}

return input
// return document
// .querySelector('pre')
// .innerHTML
.trim()
.split('\n')
.map((token) => token.split(' '))
.map(([opponent, outcome]) => [opponent, choiceLookup[opponent][outcome]])
.map(([opponent, player]) => scores.match[player][opponent] + scores.bonus[player])
.reduce((total, score) => total + score, 0)
}
Insert cell
Insert cell
import {adventOfCodeHeader, renderInput} from '@senritsu/advent-of-code-2022'
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more