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