Advent of Code 2015 Day 4
Part 1
- How about another game of Chess?
- Re-writing...
- Waiting...
How about another game of Chess?
- This puzzle is déjà vu!
- I solved it eight times as part of 2016 Day 5!
- So...solving it once should just be another waiting game!
Re-writing...
My algorithm in pseudocode:
Import my MD5 library
Set index to 0
Do as long as the first five characters in the generated hash are not zeros
Increment index by 1
My algorithm in JavaScript:
const MD5 = require('crypto-js/md5')
let index = 0, input = 'abcdef'
while (MD5(input + index).toString().slice(0,5) !== '00000') index++
return index
Waiting...
- It took a couple of seconds to run
- Then generated the correct answer!
Part 2
Six zeroes? No problem!
My algorithm in JavaScript:
const MD5 = require('crypto-js/md5')
let index = 0, input = 'abcdef'
while (MD5(input + index).toString().slice(0,6) !== '000000') index++
return index
- It took several seconds to run
- Then generated the correct answer!
I did it!!
- I solved both parts!
- Using a snippet of an algorithm I wrote in a nearly-identical puzzle from the prior year!
- I wrote what may be my shortest Advent of Code program yet, at just four lines when condensed!
Top comments (0)