Public
Edited
Dec 6, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
AOC.resultTable(meta)
Insert cell
function* options([time, distance]) {
for (let hold = 0; hold <= time; hold++)
yield { hold, speed: hold, distance: hold * (time - hold) };
}
Insert cell
winning = (race) =>
d3.reduce(
options(race),
(count, d) => count + (d.distance > race[1] ? 1 : 0),
0
)
Insert cell
part1 = (s) => s.map(winning).reduce((p, d) => p * d)
Insert cell
Insert cell
part2 = (s) =>
winning(
(which === "test1" ? test1 : input)
.trim()
.split("\n")
.map((l) => l.split(/\s+/).slice(1).join(""))
.map(Number)
)
Insert cell
data = parse(which === "test1" ? test1 : input)
Insert cell
parse = (s) =>
d3.zip(
...s
.trim()
.split("\n")
.map((l) => l.split(/\s+/).slice(1).map(Number))
)
Insert cell
Insert cell
Insert cell
inputs = ({
test: test1,
real: input
})
Insert cell
meta = AOC.meta({
day: 6,
year: 23,
title: "Wait For It",
parse,
inputs,
parts: [part1, part2],
expected: { test: [288, 71503], real: [512295, 36530883] },
href: "https://observablehq.com/@a1ip/aoc-2023-day-6"
})
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