Write a function accepting a string and returning the sum of the numbers contained in the string.
$ cat ens.rkt #lang racket (define (ens s) ; Return the sum of the numbers found in the given string. (define char->number (let ((c2n #hasheq((#\0 . 0) (#\1 . 1) (#\2 . 2) (#\3 . 3) (#\4 . 4) (#\5 . 5) (#\6 . 6) (#\7 . 7) (#\8 . 8) (#\9 . 9)))) (lambda (c) (hash-ref c2n c)))) (define (parse-number chars sum n) (if (null? chars) (+ sum n) (let ((char (car chars)) (chars (cdr chars))) (if (char-numeric? char) (parse-number chars sum (+ (* n 10) (char->number char))) (parse-letters chars (+ sum n)))))) (define (parse-letters chars sum) (if (null? chars) sum (let ((char (car chars)) (chars (cdr chars))) (if (char-numeric? char) (parse-number chars sum (char->number char)) (parse-letters chars sum))))) (parse-letters (string->list s) 0)) (require rackunit) (check-eq? (ens "") 0) (check-eq? (ens "11aa22bb33cc44") 110) (check-eq? (ens "Annual income 20 pounds, annual expenditure 19 19 and 6, result happiness") 64) $ racket ens.rkt $