Untitled

mail@pastecode.io avatar
unknown
lisp
7 months ago
476 B
4
Indexable
Never
(defun num-char-p (c)
  (<= 48 (char-code c) 57))

(defun first-last->number (str)
  (parse-integer
   (format nil "~a~a"
           (string (find-if #'num-char-p str))
           (string (find-if #'num-char-p str :from-end t)))))

(defun sum-lines (lines)
  (loop :for l :in lines
        :sum (first-last->number l)))

;; -------------------- testing --------------------
(sum-lines '("1abc2"
             "pqr3stu8vwx"
             "a1b2c3d4e5f"
             "treb7uchet"))
Leave a Comment