Public
Edited
Dec 8, 2022
1 fork
Importers
1 star
Insert cell
Insert cell
Insert cell
parse = (s) => s.trim()
Insert cell
function findFirstDistinct(s, n) {
for (let i = 0; i < s.length - n; i++) {
let set = new Set();
for (let j = 0; j < n; j++) {
if (set.has(s[i + j])) break;
set.add(s[i + j]);
}
if (set.size === n) return i + n;
}
throw new Error("not found");
}
Insert cell
part1 = (input) => findFirstDistinct(input, 4)
Insert cell
part2 = (input) => findFirstDistinct(input, 14)
Insert cell
inputs = ({
test0: "mjqjpqmgbljsphdztnvjfqwrcgsmlb",
test1: "bvwbjplbgvbhsrlpgdmjqwftvncz",
test2: "nppdvjthqldpwncqszvftbrmjlhg",
test3: "nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg",
test4: "zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw",
real: await FileAttachment("input").text()
})
Insert cell
Insert cell
import { aoc } from "@mythmon/aoc-helpers"
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