Created
December 5, 2016 18:57
-
-
Save seishun/15f815564f05763f199c4cffd948d18d to your computer and use it in GitHub Desktop.
Solution for Advent of Code 2016 day 5 part 2 in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const input = process.argv[2]; | |
console.log(input); | |
let filled = []; | |
let remaining = 8; | |
for (let index = 0; remaining; index++) { | |
let hash = crypto.createHash('md5'); | |
hash.update(input + index); | |
let digest = hash.digest('hex'); | |
if (digest.slice(0, 5) != '00000') continue; | |
let pos = +digest[5]; | |
if (!(pos >= 0 && pos <= 7) || filled[pos]) continue; | |
filled[pos] = digest[6]; | |
remaining--; | |
} | |
console.log(filled.join('')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment