Published
Edited
Dec 4, 2019
1 star
Insert cell
Insert cell
Insert cell
Insert cell
range = puzzleInput.split('-').map(Number)
Insert cell
part1 = answer(range)
Insert cell
answer = function (range) {
let a,b,c,d,e,f,pwd,N ;
let pwds = [];
for (a=0; a<10; a++) {
for (b=a; b<10; b++) {
for (c=b; c<10; c++) {
for (d=c; d<10; d++) {
for (e=d; e<10; e++) {
for (f=e; f<10; f++) {
pwd = [a,b,c,d,e,f];
if (!pwd.some( (d,i,a) => d == a[i+1] )) continue
N = Number(pwd.join(''));
if (N < range[0]) continue
if (N > range[1]) continue
pwds.push(pwd);
}
}
}
}
}
}
return {n: pwds.length, pwds: pwds};
}
Insert cell
Insert cell
part2 = {
return part1.pwds.filter(
pwd => pwd.some (
(d,i,a) => d == a[i+1] && d != a[i+2] && d != a[i-1]
)
);
}
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