Notebooks 2.0 is here.

Public
Edited
Dec 7, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
startOfPacket = [...input].findIndex((x, i, a) => new Set(a.slice(i - 4, i)).size === 4)
Insert cell
Insert cell
startOfMessage = [...input].findIndex((x, i, a) => new Set(a.slice(i - 14, i)).size === 14)
Insert cell
Insert cell
findFirstDelimiterImperative(4, input)
Insert cell
findFirstDelimiterImperative(14, input)
Insert cell
findFirstDelimiterImperative = (size, data) => {
const buffer = []
let nextIndex = 1

for (const token of data) {
if (buffer.length >= size) {
buffer.shift()
}
buffer.push(token)
if (buffer.length === size && !buffer.some((x, i) => buffer.indexOf(x) !== i)) {
return nextIndex
}
nextIndex++
}
}
Insert cell
Insert cell
findFirstDelimiterFunctional(4, input)
Insert cell
findFirstDelimiterFunctional(14, input)
Insert cell
findFirstDelimiterFunctional = (size, array) => R.findIndex(allUnique, R.aperture(size, array)) + size // R.aperture starts with the first full window, so the index offset to the original array is `size`
Insert cell
allUnique = iterable => (new Set(iterable).size) === iterable.length
Insert cell
Insert cell
R = import('ramda')
Insert cell
import {adventOfCodeHeader, renderInput} from '@senritsu/advent-of-code-2022'
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