Public
Edited
Dec 2, 2022
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
part2 = d3.sum(rounds.map(score2))
Insert cell
score2 = ([other, outcome]) => {
other = other.charCodeAt(0) - "A".charCodeAt(0);
outcome = outcomes[outcome];
const you = { 6: (other + 1) % 3, 3: other, 0: (other - 1 + 3) % 3 }[outcome];
return you + 1 + outcome;
}
Insert cell
Insert cell
outcomes = ({ X: 0, Y: 3, Z: 6 })
Insert cell
part1 = d3.sum(rounds.map(score))
Insert cell
rounds = data.trim().split("\n").map(r => r.split(" "))
Insert cell
score = ([other, you]) => {
other = other.charCodeAt(0) - "A".charCodeAt(0);
you = you.charCodeAt(0) - "X".charCodeAt(0);
const win = you === (other + 1) % 3;
return you + 1 + (win ? 6 : you === other ? 3 : 0);
}
Insert cell
sample = `
A Y
B X
C Z
`
Insert cell
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