Untitled

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

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

(defun cord-sums (lines)
  (loop :for l :in lines
        :sum (first-last-nums l)))

;; Test
(cord-sums '("1abc2"
             "pqr3stu8vwx"
             "a1b2c3d4e5f"
             "treb7uchet"))
Leave a Comment