Fixed parts for day 5
This commit is contained in:
parent
680a7fda6c
commit
b517815e30
@ -1,16 +1,13 @@
|
|||||||
var input = require("fs").readFileSync("input.txt").toString().replace(/\n/g, "").replace(/\r/g, "");
|
var input = require("fs").readFileSync("input.txt").toString().replace(/\n/g, "").replace(/\r/g, "");
|
||||||
var password = [];
|
var password = [];
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(password.filter((a)=>(a)).length < 8){
|
while(password.length < 8){
|
||||||
var md5sum = require("crypto").createHash("md5");
|
var md5sum = require("crypto").createHash("md5");
|
||||||
md5sum.update(input + i);
|
md5sum.update(input + i);
|
||||||
var hash = md5sum.digest("hex");
|
var hash = md5sum.digest("hex");
|
||||||
if(hash.slice(0, 5) == "00000"){
|
if(hash.slice(0, 5) == "00000"){
|
||||||
var position = parseInt(hash[5]);
|
password.push(hash[5]);
|
||||||
if(!password[position] && position <= 7){
|
console.log("FOUND", i, password.length);
|
||||||
password[position] = hash[6];
|
|
||||||
console.log("FOUND", i, password.length, position, hash);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
if(i%100000 == 0){
|
if(i%100000 == 0){
|
||||||
|
20
day05/part2.js
Normal file
20
day05/part2.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
var input = require("fs").readFileSync("input.txt").toString().replace(/\n/g, "").replace(/\r/g, "");
|
||||||
|
var password = [];
|
||||||
|
var i = 0;
|
||||||
|
while(password.filter((a)=>(a)).length < 8){
|
||||||
|
var md5sum = require("crypto").createHash("md5");
|
||||||
|
md5sum.update(input + i);
|
||||||
|
var hash = md5sum.digest("hex");
|
||||||
|
if(hash.slice(0, 5) == "00000"){
|
||||||
|
var position = parseInt(hash[5]);
|
||||||
|
if(!password[position] && position <= 7){
|
||||||
|
password[position] = hash[6];
|
||||||
|
console.log("FOUND", i, password.length, position, hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
if(i%100000 == 0){
|
||||||
|
console.log(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(password.join(""));
|
Loading…
x
Reference in New Issue
Block a user