diff options
author | Oscar Najera <hi@oscarnajera.com> | 2022-12-06 16:47:44 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2022-12-06 16:47:44 +0100 |
commit | f34c85b78a1cbefa475a252184c13b68c9727332 (patch) | |
tree | 11b7b49735ca72adca4701f5f0a7619d6ed9bd6c /AoC2022/06/solver.lisp | |
parent | 48fd41b4a011d04634830c9132cf137d33ad555a (diff) | |
download | scratch-f34c85b78a1cbefa475a252184c13b68c9727332.tar.gz scratch-f34c85b78a1cbefa475a252184c13b68c9727332.tar.bz2 scratch-f34c85b78a1cbefa475a252184c13b68c9727332.zip |
[AoC2022] Lisp 06
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) |