more simplification

main
Inga 🏳‍🌈 10 months ago
parent 424fc84499
commit d742bc5e7f
  1. 38
      day01-easy/main.scm

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

Loading…
Cancel
Save