Published
Edited
Dec 12, 2020
1 fork
1 star
Insert cell
Insert cell
groups = input.trim().split('\n\n').map(g => g.split('\n'))
Insert cell
part1 = groups.map(g => new Set(g.flatMap(s => s.split(''))))
.reduce((sum, set) => sum + set.size, 0)
Insert cell
part2 = groups.map(g => g.map(s => new Set(s.split(''))))
.map(g => g.reduce((r, s) => intersect(r, new Set(s))))
.reduce((sum, set) => sum + set.size, 0)
Insert cell
intersect = (s1, s2) => new Set(Array.from(s1).filter(x => s2.has(x)))
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