advent-of-code/2023/1/main-1.lisp

24 lines
555 B
Common Lisp
Raw Normal View History

2023-12-01 22:41:12 -08:00
(defpackage #:aoc-2023/1.1
(:use #:cl)
(:export #:main))
(in-package #:aoc-2023/1.1)
(defun digits-to-integer (a b)
(values (parse-integer (format NIL "~A~A" a b))))
(defun line-value (line)
(digits-to-integer (find-if #'digit-char-p line)
(find-if #'digit-char-p line :from-end T)))
(defun main ()
(format T
"~A~%"
(loop :for line := (read-line T NIL)
:while line
:unless (string= line "")
:sum (line-value line))))
(eval-when (:execute)
(main))