Public
Edited
May 6, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
MD5Lib = require("hash-wasm@4.9.0/dist/md5.umd.min.js")
Insert cell
Insert cell
async function findPassword(doorId) {
let [i, pwd] = [0, ""];
while (pwd.length < 8) {
const hash = await MD5Lib.md5(doorId + i++);
if (hash.startsWith("00000")) {
pwd += hash[5];
}
}
return pwd;
}
Insert cell
part1 = "Uncomment findPassword line for answer (takes c. 8 seconds)" //findPassword(puzzleInput)
Insert cell
Insert cell
Insert cell
Insert cell
async function findPassword2(doorId) {
let [i, foundChrs] = [0, 0];
const pwd = Array(8).fill(null);
while (foundChrs < 8) {
const hash = await MD5Lib.md5(doorId + i++);
if (hash.startsWith("00000")) {
const position = parseInt(hash[5], 16);
if (position < 8 && pwd[position] === null) {
pwd[position] = hash[6];
foundChrs++;
}
}
}
return pwd.join("");
}
Insert cell
part2 = "Uncomment findPassword2 line for answer (takes c. 25 seconds)" //findPassword2(puzzleInput)
Insert cell
Insert cell
Insert cell
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