|
|
@ -16,6 +16,12 @@ |
|
|
|
'() |
|
|
|
'() |
|
|
|
(cons (mapper (car list)) (map (cdr list) mapper)))) |
|
|
|
(cons (mapper (car list)) (map (cdr list) mapper)))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (reduce list reducer current) |
|
|
|
|
|
|
|
(if |
|
|
|
|
|
|
|
(null? list) |
|
|
|
|
|
|
|
current |
|
|
|
|
|
|
|
(reduce (cdr list) reducer (reducer current (car list))))) |
|
|
|
|
|
|
|
|
|
|
|
(define (first-last-combine current rest) |
|
|
|
(define (first-last-combine current rest) |
|
|
|
(if |
|
|
|
(if |
|
|
|
(null? current) |
|
|
|
(null? current) |
|
|
@ -36,26 +42,16 @@ |
|
|
|
'()) |
|
|
|
'()) |
|
|
|
(first-last (cdr list) predicate)))) |
|
|
|
(first-last (cdr list) predicate)))) |
|
|
|
|
|
|
|
|
|
|
|
(define (sum numbers) |
|
|
|
(define (sum numbers) (reduce numbers + 0)) |
|
|
|
(if |
|
|
|
|
|
|
|
(null? numbers) |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
(+ (car numbers) (sum (cdr numbers))) |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (solve-line line) |
|
|
|
(define (solve-line line) |
|
|
|
( |
|
|
|
( |
|
|
|
#!(lambda (first-last-result) (sum (map first-last-result (lambda (char) (string->number (string char))))))!# |
|
|
|
|
|
|
|
(lambda (first-last-result) (string->number (list->string first-last-result))) |
|
|
|
(lambda (first-last-result) (string->number (list->string first-last-result))) |
|
|
|
(first-last |
|
|
|
(first-last |
|
|
|
(string->list line) |
|
|
|
(string->list line) |
|
|
|
(lambda (char) (if (char-numeric? char) #t #f))))) |
|
|
|
(lambda (char) (if (char-numeric? char) #t #f))))) |
|
|
|
|
|
|
|
|
|
|
|
(define (solve-all lines) |
|
|
|
(define (solve-all lines) |
|
|
|
(if |
|
|
|
(sum (map lines solve-line))) |
|
|
|
(null? lines) |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
(+ (solve-line (car lines)) (solve-all (cdr lines))) |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(display (solve-all (read-lines))) |
|
|
|
(display (solve-all (read-lines))) |
|
|
|