adventofcode-2016/day05/part1.js

18 lines
474 B
JavaScript
Raw Normal View History

2016-12-05 08:22:12 +00:00
var input = require("fs").readFileSync("input.txt").toString().replace(/\n/g, "").replace(/\r/g, "");
var password = [];
var i = 0;
2016-12-05 08:34:19 +00:00
while(password.length < 8){
2016-12-05 08:22:12 +00:00
var md5sum = require("crypto").createHash("md5");
md5sum.update(input + i);
var hash = md5sum.digest("hex");
if(hash.slice(0, 5) == "00000"){
2016-12-05 08:34:19 +00:00
password.push(hash[5]);
console.log("FOUND", i, password.length);
2016-12-05 08:22:12 +00:00
}
i++;
if(i%100000 == 0){
console.log(i);
}
}
console.log(password.join(""));