--- a/advent.asd Sat Dec 07 16:58:49 2019 -0500
+++ b/advent.asd Sat Dec 07 18:41:25 2019 -0500
@@ -21,17 +21,20 @@
:1am
:alexandria
:beast
+ :bordeaux-threads
:cl-digraph
:cl-digraph.dot
:cl-interpol
:cl-ppcre
:iterate
+ :jpl-queues
:losh
+ :md5
+ :ironclad
:named-readtables
:pileup
:split-sequence
:str
- :jpl-queues
)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/data/2016/05.txt Sat Dec 07 18:41:25 2019 -0500
@@ -0,0 +1,1 @@
+uqwqemis
--- a/package.lisp Sat Dec 07 16:58:49 2019 -0500
+++ b/package.lisp Sat Dec 07 18:41:25 2019 -0500
@@ -38,6 +38,9 @@
:let-complex
:queue-thunk
+ :bytes->hex
+ :bytes->integer
+
:ring
:ring-prev
:ring-next
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/2016/days/day-05.lisp Sat Dec 07 18:41:25 2019 -0500
@@ -0,0 +1,33 @@
+(defpackage :advent/2016/05 #.cl-user::*advent-use*)
+(in-package :advent/2016/05)
+
+(defun md5 (string)
+ (bytes->hex (md5:md5sum-string string)))
+
+(define-problem (2016 5) (data read-line) ("1a3099aa" "694190cd")
+ (iterate
+ (with part1 = (make-array 8 :element-type 'character :initial-element #\_ :fill-pointer 0))
+ (with part2 = (make-string 8 :initial-element #\_))
+ (with remaining = 8)
+ (with spinner = '#1=(#\◴ #\◷ #\◶ #\◵ . #1#))
+ (returning part1 part2)
+ (for i :from 0)
+ (for hash = (md5 (format nil "~A~D" data i)))
+ (when (dividesp i 100000)
+ (format t "~C~C Iteration: ~D" #\Return (pop spinner) i)
+ (force-output))
+ (when (str:starts-with-p "00000" hash)
+ (when (< (length part1) 8)
+ (vector-push (aref hash 5) part1))
+ (let ((pos (digit-char-p (aref hash 5) 16)))
+ (when (and (< pos (length part2))
+ (char= (aref part2 pos) #\_))
+ (setf (aref part2 pos) (aref hash 6))
+ (when (zerop (decf remaining))
+ (format t " Cracked.~%")
+ (finish))))
+ (format t " [~A] / [~A]~%" part1 part2))))
+
+
+
+#; Scratch --------------------------------------------------------------------
--- a/src/2017/knot-hash.lisp Sat Dec 07 16:58:49 2019 -0500
+++ b/src/2017/knot-hash.lisp Sat Dec 07 18:41:25 2019 -0500
@@ -27,15 +27,6 @@
(for i :from 0 :by 16 :below (length numbers))
(collect (reduce #'logxor numbers :start i :end (+ i 16)))))
-(defun bytes->hex (bytes)
- (format nil "~(~{~2,'0X~}~)" bytes))
-
-(defun bytes->integer (bytes)
- (iterate
- (for byte :in bytes)
- (for result :seed 0 :then (+ (ash result 8) byte))
- (returning result)))
-
(defun initial-lengths (string)
(append (map 'list #'char-code string)
(list 17 31 73 47 23)))
--- a/src/utils.lisp Sat Dec 07 16:58:49 2019 -0500
+++ b/src/utils.lisp Sat Dec 07 18:41:25 2019 -0500
@@ -478,6 +478,16 @@
(lambda () (pop elements)))
+(defun bytes->hex (bytes)
+ (format nil "~(~{~2,'0X~}~)" (coerce bytes 'list)))
+
+(defun bytes->integer (bytes)
+ (iterate
+ (for byte :in (coerce bytes 'list))
+ (for result :seed 0 :then (+ (ash result 8) byte))
+ (returning result)))
+
+
;;;; A* Search ----------------------------------------------------------------
(defstruct path
state