Published
Edited
Nov 13, 2019
Insert cell
Insert cell
part2 = {
let max = 0
for (let { score } of scores(455, 7122300))
if (score > max)
max = score
return max
}
Insert cell
part1 = {
let max = 0
for (let { score } of scores(455, 71223))
if (score > max)
max = score
return max
}
Insert cell
Insert cell
function trend(x) { return 6.307e-5*(x*x) + 0.8882*x + 160.16 }
Insert cell
Insert cell
function* scores(players, marbles) {
const circle = [ 0 ]
const scores = _.range(0, players).map(n => 0)

let current = { value: 0 }
current.next = current.prev = current
for (let i = 1; i <= marbles; i++) {
const player = (i-1) % players
if (i % 23 === 0) {
scores[player] += i
let remove = current
for (let j = 0; j < 7; j++)
remove = remove.prev
scores[player] += remove.value
remove.prev.next = remove.next
remove.next.prev = remove.prev
current = remove.next
yield { i, player, score: scores[player] }
} else {
const place = current.next
place.next = place.next.prev = {
value: i,
next: place.next,
prev: place
}
current = place.next
}
}
}
Insert cell
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