Public
Edited
Dec 8, 2022
1 fork
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
tidy = next1.flatMap((s, x) => s.map((p, height) => ({ x, height, p })))
Insert cell
part2 = next2.map(s => s[s.length - 1]).join("")
Insert cell
next2 = {
const next = stacks.map((s) => s.slice());
for (const [n, from, to] of moves)
next[to - 1] = next[to - 1].concat(next[from - 1].splice(-n, n));
return next;
}
Insert cell
part1 = next1.map(s => s[s.length - 1]).join("")
Insert cell
next1 = {
refresh;
const next = stacks.map((s) => s.slice());
for (const [n, from, to] of moves) {
for (let i = 0; i < n; i++) {
next[to - 1].push(next[from - 1].pop());
yield next;
}
}
return next;
}
Insert cell
moves = parsed[1].filter(d => d).map(l => l.match(/move (\d+) from (\d+) to (\d+)/).slice(1).map(Number))
Insert cell
stacks = {
const levels = parsed[0].slice(0, -1).map((s) =>
s
.replace(/ {4}/g, "[] ")
.match(/\[\w?\]/g)
.map((d) => d.replace(/[\[\]]/g, ""))
);
return d3.transpose(levels).map((s) => s.filter((d) => d).reverse());
}
Insert cell
parsed = data
.slice(1)
.split("\n\n")
.map((l) => l.split("\n"))
Insert cell
sample = `
[D]
[N] [C]
[Z] [M] [P]
1 2 3

move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
`
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