Count consecutive increases in the sum of three consecutive values.
$ cat 01b.rkt #lang racket (require (prefix-in aoc01: "01a.rkt") (prefix-in srfi1: srfi/1)) (define (aoc01b . input) ; Return the number of increases in the sums of three ; consecutive depth soundings. If no soundings are given, use ; the contest problem input; otherwise assume the argument is ; the string representation of a problem input. (increasing-count (apply aoc01:read-input input) 3)) (define (increasing-count soundings window-size) ; Return the number of depth increases from window to window in ; the given sequence of depth soundings. (length (filter (lambda (p) (apply < p)) (srfi1:zip soundings (drop soundings window-size))))) (module+ main (aoc01b)) (define example-result 5) (module+ test (require rackunit) (check-equal? (aoc01b aoc01:example-data) example-result) (check-equal? (aoc01b) 1575)) $ raco test 01b.rkt raco test: (submod "01b.rkt" test) 2 tests passed $