src/2018/days/day-02.lisp @ 2848a4548adf

2023/01 and 2022/01

Also start porting my test data to the new account, since Twitter imploded and
apparently it's impossible for a website to store a goddamn username and
password in The Year of Our Lord 2023 so everyone just outsources auth all
the time, ugh.
author Steve Losh <steve@stevelosh.com>
date Fri, 01 Dec 2023 11:05:43 -0500
parents 182bdd87fd9e
children (none)
(advent:defpackage* :advent/2018/02)
(in-package :advent/2018/02)


(define-problem (2018 2) (data read-lines) (8296 "pazvmqbftrbeosiecxlghkwud")
  (values
    (let* ((freqs (mapcar #'frequencies data))
           (counts (mapcar #'alexandria:hash-table-values freqs)))
      (* (count 2 counts :test #'member)
         (count 3 counts :test #'member)))
    ;; just brute force it
    (multiple-value-bind (a b)
        (iterate
          (for (a . remaining) :on data)
          (for b = (find 1 remaining :key (curry #'hamming-distance a)))
          (when b
            (return (values a b))))
      (let ((i (mismatch a b)))
        (str:concat (subseq a 0 i)
                    (subseq a (1+ i)))))))