simplified compose

main
Inga 🏳‍🌈 12 months ago
parent 80aa85f17b
commit 46167adb2c
  1. 34
      day01-easy/main.scm

@ -12,20 +12,19 @@
(define (id value) value)
(define (compose result-transformer f argument-transformer)
(lambda (value)
(result-transformer (f (argument-transformer value)))))
(define Y (lambda (f) (f (lambda (x) ((Y f) x)))))
(define (reduce-right reducer initial) (Y
(lambda (f) (lambda (list)
(if (null? list) initial (reducer (car list) (f (cdr list))))))))
(define (map mapper)
(reduce-right
(lambda (current accumulator) (cons (mapper current) accumulator))
'()))
(define (map mapper) (reduce-right
(lambda (current accumulator) (cons (mapper current) accumulator))
'()))
(define compose (reduce-right
(lambda (current accumulator) (lambda (value) (current (accumulator value))))
id))
(define (combine combiner)
(lambda (a b) (if (null? a) b (if (null? b) a (combiner a b)))))
@ -36,20 +35,17 @@
(lambda (f) (lambda (n)
(if (= n 0) '() (cons value (f (- n 1))))))))
(define (is-numeric-char char) (if (char-numeric? char) #t #f))
(define (first-last predicate) (compose
id
(define solve-line (compose (list
string->number
list->string
(reduce-right
(combine (lambda (left right) (cons (car left) (cdr right))))
'())
(map (lambda (entry) (if (predicate entry) ((repeat entry) 2) '())))))
(define solve-line (compose
(lambda (first-last-result) (string->number (list->string first-last-result)))
(first-last is-numeric-char)
string->list))
(map (lambda (char) (if (char-numeric? char) ((repeat char) 2) '())))
string->list)))
(define (solve-all lines) (sum ((map solve-line) lines)))
(define solve-all (compose (list
sum
(map solve-line))))
(display (solve-all (read-lines)))

Loading…
Cancel
Save