Untitled

mail@pastecode.io avatar
unknown
lisp
6 months ago
512 B
1
Indexable
Never
(ql:quickload :str)

(defun num-char-p (c)
  (<= 48 (char-code c) 57))
     
(defun first-last->number (str)
  (let ((s (str:words
            (substitute-if-not #\SPACE #'num-char-p str))))
    (parse-integer (concatenate 'string (first s) (car (last s))))))

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

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