Day 4, Part 2

This commit is contained in:
Correl Roush 2015-12-11 07:57:13 -05:00 committed by Correl Roush
parent 22b37435f0
commit 696932fa77

View file

@ -1470,5 +1470,29 @@ For example:
(day4/first-adventcoin (string-trim input)) (day4/first-adventcoin (string-trim input))
#+END_SRC #+END_SRC
#+RESULTS[5929e5d34f2976d5204f75afe31ef59b06411f6d]: #+RESULTS[461139efd69152ff32f7ba3996d41b323fd6c8bd]:
: 117946 : 117946
** Part 2
Now find one that starts with *six zeroes*.
----------------------------------------------------------------------
#+BEGIN_SRC emacs-lisp :var input=4-input :exports both
(defun day4/adventcoin-hash-6-p (n hash)
(string-equal
"000000"
(substring hash 0 6)))
(defun day4/first-adventcoin-n (n secret)
(loop for x from 0
while (not (day4/adventcoin-hash-6-p n (day4/mine-hash secret x)))
count x))
(day4/first-adventcoin-n 6 (string-trim input))
#+END_SRC
#+RESULTS[637ec8d92dd6b49b39e0eb247af8265cd6938e5a]:
: 3938038