r/adventofcode • • Dec 04 '15

SOLUTION MEGATHREAD --- Day 4 Solutions ---

--- Day 4: The Ideal Stocking Stuffer ---

Post your solution as a comment. Structure your post like the Day Three thread.

14 Upvotes

272 comments sorted by

View all comments

Show parent comment

1

u/joeyrobert Dec 04 '15

Also JavaScript using a different md5 library:

'use strict';

const md5 = require('md5');
let secret = 'yzbqklnj';
let beginnings = ['00000', '000000'];

beginnings.forEach(beginning => {
    for (let counter = 1;; counter++) {
        let hashed = md5(secret + counter);

        if (hashed.substr(0, beginning.length) === beginning) {
            console.log(hashed, counter);
            break;
        }
    }
});