blob: fbcbf77b5e42991ab17e481512aa0df4f1dfb358 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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!)
|