Untitled
unknown
lisp
2 years ago
476 B
7
Indexable
(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"))Editor is loading...
Leave a Comment