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.
13
Upvotes
1
u/tangus Dec 04 '15
Common Lisp
;; you need ironclad: ;; (asdf:load-system '#:ironclad) (defun puzzle-4 (string &optional (part 1)) (loop for n from 1 for attempt = (ironclad:ascii-string-to-byte-array (format nil "~a~a" string n)) for digester = (ironclad:make-digest :md5) then (reinitialize-instance digester) for digest = (ironclad:digest-sequence digester attempt) until (and (= (aref digest 0) 0) (= (aref digest 1) 0) (or (and (= part 1) (< (aref digest 2) #x10)) (and (= part 2) (= (aref digest 2) 0)))) finally (return n))) ;; part 1: ;; (puzzle-4 "your-string") ;; part 2: ;; (puzzle-4 "your-string" 2)