aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/06/solver.lisp
blob: 11759ff6f783495a7a1d5e1f55e728c5392c4b59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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))))