diff options
Diffstat (limited to 'AoC2023/day15/solver.lisp')
-rw-r--r-- | AoC2023/day15/solver.lisp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/AoC2023/day15/solver.lisp b/AoC2023/day15/solver.lisp new file mode 100644 index 0000000..fbcbf77 --- /dev/null +++ b/AoC2023/day15/solver.lisp @@ -0,0 +1,23 @@ +;; 17:04 +;; 17:34 part1 +(ql:quickload '(fiveam str)) + +(defparameter eg-in "rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7") + +(defun hash (str) + (reduce + (lambda (acc c) + (mod (* 17 (+ acc (char-code c))) 256)) + str :initial-value 0)) + +(defun solve1 (in) + (reduce #'+ + (str:split "," (str:trim in)) + :key #'hash)) + +(fiveam:test solutions + (fiveam:is (= 52 (hash "HASH"))) + (fiveam:is (= 1320 (solve1 eg-in))) + (fiveam:is (= 506437 (solve1 (uiop:read-file-string "input"))))) + +(fiveam:run!) |