From 3aff1cd302e2c2488daaf4b89b2aa587a2d9e5a9 Mon Sep 17 00:00:00 2001 From: Alan Daniels Date: Sat, 6 Dec 2025 18:46:23 +1100 Subject: [PATCH] day 3 part 1 --- 03a.lisp | 23 +++++++++++++++++++++++ 03example.txt | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 03a.lisp create mode 100644 03example.txt diff --git a/03a.lisp b/03a.lisp new file mode 100644 index 0000000..8add288 --- /dev/null +++ b/03a.lisp @@ -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")) diff --git a/03example.txt b/03example.txt new file mode 100644 index 0000000..7255fca --- /dev/null +++ b/03example.txt @@ -0,0 +1,4 @@ +987654321111111 +811111111111119 +234234234234278 +818181911112111