diff options
Diffstat (limited to 'AoC2022/06/solver.lisp')
-rw-r--r-- | AoC2022/06/solver.lisp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/AoC2022/06/solver.lisp b/AoC2022/06/solver.lisp new file mode 100644 index 0000000..36aab05 --- /dev/null +++ b/AoC2022/06/solver.lisp @@ -0,0 +1,17 @@ + +(defun solver (marker-size) + (with-open-file (in "input" :element-type 'unsigned-byte) + (loop with acc = (make-array marker-size :element-type 'unsigned-byte) + for char = (ash 1 (- (read-byte in) 96)) ;; all lowercase letters thus subtract ascii start + and idx from 1 + do (setf (aref acc (mod idx marker-size)) char) + when (<= marker-size (logcount (reduce (lambda (set v) (logxor set v)) acc))) + return idx))) + +(ql:quickload :fiveam) + +(fiveam:test results + (fiveam:is (= 1655 (solver 4))) + (fiveam:is (= 2665 (solver 14)))) + +(fiveam:run-all-tests) |