alexandria-ocasio-cortez axiom-of-choice area-of-concern american-orthodox-church almost-optimal-coset solutions in the year of our lord 2021, I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
775 B

#lang racket
(require "lib/common.rkt")
(define (sum lst) (foldr + 0 lst))
(define (day1a lst)
(for/sum ([v (in-list lst)]
[next (in-list (rest lst))])
(if (< v next) 1 0)))
(define (day1b lst)
(define sum-list
(let loop ([current-lst lst])
(cond [(< (length current-lst) 3) empty]
[else (cons (sum (take current-lst 3))
(loop (rest current-lst)))])))
(day1a sum-list))
(module+ main
(call-with-input-file "data/day1.txt"
(lambda (prt)
(define lines (map string->number (port->lines prt)))
(answer 1 1 (day1a lines))
(answer 1 2 (day1b lines)))))
(module+ test
(require rackunit)
(define lines '(199 200 208 210 200 207 240 269 260 263))
(check-equal? (day1b lines) 5))