more simplification

main
Inga 🏳‍🌈 12 months ago
parent 5443e45700
commit 827d301949
  1. 27
      day01-easy/main.scm

@ -22,29 +22,32 @@
current current
(reduce (cdr list) reducer (reducer current (car list))))) (reduce (cdr list) reducer (reducer current (car list)))))
(define (first-last-combine current rest) (define (combine list combiner)
(if (if
(null? current) (null? (car list))
rest (cdr list)
(if (if
(null? rest) (null? (cdr list))
current (car list)
(cons (car current) (cdr rest))))) (combiner (car list) (cdr list)))))
(define (sum numbers) (reduce numbers + 0))
(define (is-numeric-char char) (if (char-numeric? char) #t #f))
(define (first-last list predicate) (define (first-last list predicate)
(if (if
(null? list) (null? list)
'() '()
(first-last-combine (combine
(cons
(if (if
(predicate (car list)) (predicate (car list))
(cons (car list) (cons (car list) '())) (cons (car list) (cons (car list) '()))
'()) '())
(first-last (cdr list) predicate)))) (first-last (cdr list) predicate))
(lambda (current rest)
(define (sum numbers) (reduce numbers + 0)) (cons (car current) (cdr rest))))))
(define (is-numeric-char char) (if (char-numeric? char) #t #f))
(define (solve-line line) (define (solve-line line)
( (

Loading…
Cancel
Save