Published
Edited
Dec 9, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const layers = input.match(/\d{150}/g);
let min = input.length;
let checksum;
layers.forEach((layer) => {
if (layer.match(/0/g).length < min) {
min = layer.match(/0/g).length;
checksum = layer.match(/1/g).length * layer.match(/2/g).length;
}
});
return checksum;
}
Insert cell
Insert cell
{
const layers = input.match(/\d{150}/g);
let decoded = '\n';
for (let i = 0; i < width * height; i++) {
if (i >= width && i % width === 0) {
decoded += '\n';
}
// find first non-transparent picture in layer stack at pos i
let layer = 0;
let pixel = layers[layer][i];
while (pixel == 2 && layer < layers.length) {
layer++;
pixel = layers[layer][i];
}
decoded += `${pixel === '1' ? '🟨' : '⬛'}`;
}
return decoded;
}
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