src/2017/days/day-04.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/2017/04) (in-package :advent/2017/04) (defun valid-hash-table-test-p (test) (member test `(eq eql equal equalp ,#'eq ,#'eql ,#'equal ,#'equalp))) (defun ensure-boolean (value) (if value t nil)) (defun contains-duplicates-p (sequence &key (test #'eql)) (ensure-boolean (if (valid-hash-table-test-p test) (iterate (with seen = (make-hash-set :test test)) (for value :in-whatever sequence) (thereis (hset-contains-p seen value)) (hset-insert! seen value)) (etypecase sequence (list (iterate (for (value . remaining) :on sequence) (thereis (position value remaining :test test)))) (sequence (iterate (for i :from 0 :below (length sequence)) (for value = (elt sequence i)) (thereis (position value sequence :start (1+ i) :test test)))))))) (defun anagramp (string1 string2) (string= (sort (copy-seq string1) #'char<) (sort (copy-seq string2) #'char<))) (define-problem (2017 4) (data read-lines-of-words) (337 231) (values (count-if (lambda (phrase) (not (contains-duplicates-p phrase :test #'equal))) data) (count-if (lambda (phrase) (not (contains-duplicates-p phrase :test #'anagramp))) data)))