day 3 part 1

This commit is contained in:
Alan Daniels 2025-12-06 18:46:23 +11:00
parent 933f2367d5
commit 3aff1cd302
2 changed files with 27 additions and 0 deletions

23
03a.lisp Normal file
View file

@ -0,0 +1,23 @@
(require :uiop)
(load (sb-ext:posix-getenv "ASDF"))
(asdf:load-system 'str)
(defun bank-max-joltage (bank)
(let ((batt-len (- (length bank) 1)))
(apply #'max
(loop for batt-first from 0 to (- batt-len 1)
collect (apply #'max
(loop for batt-last from (+ batt-first 1) to batt-len
collect (let (
(first-char (subseq bank batt-first (+ batt-first 1)))
(last-char (subseq bank batt-last (+ batt-last 1))))
(parse-integer (format nil "~A~A" first-char last-char)))))))))
(bank-max-joltage "987654321111111")
(defun array-total-joltage (bank-list)
(reduce #'+
(mapcar #'bank-max-joltage bank-list)))
(array-total-joltage (uiop:read-file-lines "03example.txt"))
(array-total-joltage (uiop:read-file-lines "03data.txt"))

4
03example.txt Normal file
View file

@ -0,0 +1,4 @@
987654321111111
811111111111119
234234234234278
818181911112111