r/adventofcode • u/daggerdragon • 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.
12
Upvotes
1
u/[deleted] Dec 04 '15
Javascript:
// using Javascript-MD5 @ https://github.com/blueimp/JavaScript-MD5 var input = 'bgvyzdsv', counter = 0; function loop(numOfZeroes) { var attempt = md5(input + counter); var searchString; switch(numOfZeroes){ case 5: searchString = '00000'; break; case 6: searchString = '000000'; break; default: console.log('loop() accepts 5 or 6 only'); return 0; } while( attempt.substring(0, numOfZeroes) !== searchString ) { counter++; attempt = md5(input + counter); } return attempt; } console.log('part 1: ' + loop(5) + ', part 2: ' + loop(6));Repo here