Published
Edited
Dec 13, 2021
1 star
Insert cell
Insert cell
Insert cell
part2 = d3.count(
paths(["start"], (steps) => (p) =>
p !== "start" &&
steps[steps.length - 1] !== "end" &&
(isTitleCase(p) ||
!steps.includes(p) ||
d3.every(
d3
.rollup(
steps.filter((p) => p[0].toUpperCase() !== p[0]),
(r) => r.length,
(d) => d
)
.values(),
(n) => n === 1
))
),
(d) => !!d
)
Insert cell
part1 = d3.count(
paths(["start"], (steps) => (p) => isTitleCase(p) || !steps.includes(p)),
(d) => !!d
)
Insert cell
function* paths(steps, canVisit) {
if (steps[steps.length - 1] === "end") yield steps;
const possible = edges.get(steps[steps.length - 1]).filter(canVisit(steps));
for (const next of possible) yield* paths(steps.concat(next), canVisit);
}
Insert cell
isTitleCase = (s) => s[0] === s[0].toUpperCase()
Insert cell
edges = d3.rollup(data.concat(data.map(p => p.slice().reverse())), r => r.map(d => d[1]), d => d[0])
Insert cell
data = input.trim().split("\n").map((l) => l.split("-"))
Insert cell
test = `start-A
start-b
A-c
A-b
b-d
A-end
b-end`
Insert cell
test2 = `fs-end
he-DX
fs-he
start-DX
pj-DX
end-zg
zg-sl
zg-pj
pj-he
RW-he
fs-DX
pj-RW
zg-RW
start-pj
he-WI
zg-he
pj-fs
start-RW`
Insert cell
Insert cell
import { ForceGraph } from "@d3/force-directed-graph"
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