simplified code

main
Inga 🏳‍🌈 11 months ago
parent adb0515460
commit 1915978029
  1. 20
      day01-easy/main.scm

@ -16,6 +16,12 @@
'()
(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)
(if
(null? current)
@ -36,26 +42,16 @@
'())
(first-last (cdr list) predicate))))
(define (sum numbers)
(if
(null? numbers)
0
(+ (car numbers) (sum (cdr numbers)))
))
(define (sum numbers) (reduce numbers + 0))
(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)))
(first-last
(string->list line)
(lambda (char) (if (char-numeric? char) #t #f)))))
(define (solve-all lines)
(if
(null? lines)
0
(+ (solve-line (car lines)) (solve-all (cdr lines)))
))
(sum (map lines solve-line)))
(display (solve-all (read-lines)))

Loading…
Cancel
Save