|
|
|
@ -22,14 +22,14 @@ |
|
|
|
|
current |
|
|
|
|
(reduce (cdr list) reducer (reducer current (car list))))) |
|
|
|
|
|
|
|
|
|
(define (combine list combiner) |
|
|
|
|
(define (combine a b combiner) |
|
|
|
|
(if |
|
|
|
|
(null? (car list)) |
|
|
|
|
(cdr list) |
|
|
|
|
(null? a) |
|
|
|
|
b |
|
|
|
|
(if |
|
|
|
|
(null? (cdr list)) |
|
|
|
|
(car list) |
|
|
|
|
(combiner (car list) (cdr list))))) |
|
|
|
|
(null? b) |
|
|
|
|
a |
|
|
|
|
(combiner a b)))) |
|
|
|
|
|
|
|
|
|
(define (sum numbers) (reduce numbers + 0)) |
|
|
|
|
|
|
|
|
@ -43,22 +43,20 @@ |
|
|
|
|
(define (is-numeric-char char) (if (char-numeric? char) #t #f)) |
|
|
|
|
|
|
|
|
|
(define (first-last list predicate) |
|
|
|
|
(if |
|
|
|
|
(null? list) |
|
|
|
|
'() |
|
|
|
|
(reduce |
|
|
|
|
(map list (lambda (entry) |
|
|
|
|
(if (predicate entry) (repeat entry 2) '()))) |
|
|
|
|
(lambda (current accumulator) |
|
|
|
|
(combine |
|
|
|
|
(cons |
|
|
|
|
(if |
|
|
|
|
(predicate (car list)) |
|
|
|
|
(repeat (car list) 2) |
|
|
|
|
'()) |
|
|
|
|
(first-last (cdr list) predicate)) |
|
|
|
|
current |
|
|
|
|
accumulator |
|
|
|
|
(lambda (current rest) |
|
|
|
|
(cons (car current) (cdr rest)))))) |
|
|
|
|
(cons (car current) (cdr rest))))) |
|
|
|
|
'())) |
|
|
|
|
|
|
|
|
|
(define (solve-line line) |
|
|
|
|
( |
|
|
|
|
(lambda (first-last-result) (string->number (list->string first-last-result))) |
|
|
|
|
((lambda (first-last-result) |
|
|
|
|
(string->number (list->string first-last-result))) |
|
|
|
|
(first-last (string->list line) is-numeric-char))) |
|
|
|
|
|
|
|
|
|
(define (solve-all lines) |
|
|
|
|