Public
Edited
Nov 29, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
function parse(input) {
const g = new Graph();
for (const line of input.split("\n")) {
const [n1, rest] = line.split(/\s+<->\s+/);
for (const n2 of rest.split(/,\s+/)) {
g.addEdge(n1, n2);
}
}
return g;
}
Insert cell
Insert cell
function part1(input) {
return parse(input).breadthFirstSearch("0").length;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
return parse(input).nodes(true).length;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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