Skip to content

Instantly share code, notes, and snippets.

@seishun
Created December 5, 2016 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seishun/15f815564f05763f199c4cffd948d18d to your computer and use it in GitHub Desktop.
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
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