aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2023/day15/solver.lisp
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-12-16 17:34:59 +0100
committerOscar Najera <hi@oscarnajera.com>2023-12-16 17:37:19 +0100
commit8193fd33c3e84a02adb465a029ba271902deb43b (patch)
tree628db53132c621ef54388d91187ba90ee3b387f4 /AoC2023/day15/solver.lisp
parentf5a6dc8ec1d3cc6e04409401fde5aad696f33eba (diff)
downloadscratch-8193fd33c3e84a02adb465a029ba271902deb43b.tar.gz
scratch-8193fd33c3e84a02adb465a029ba271902deb43b.tar.bz2
scratch-8193fd33c3e84a02adb465a029ba271902deb43b.zip
day15 part 1
Diffstat (limited to 'AoC2023/day15/solver.lisp')
-rw-r--r--AoC2023/day15/solver.lisp23
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!)