You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
aoc-racket/2021/01.rkt

20 lines
553 B
Racket

2 years ago
#lang br
(require racket/file rackunit)
(define depths (map string->number (file->lines "01.rktd")))
(define (positive-deltas depths)
(filter positive?
(for/list ([d1 (in-list depths)]
[d2 (in-list (cdr depths))])
(- d2 d1))))
(check-equal? (length (positive-deltas depths)) 1167)
(define (trios depths)
(for/list ([d1 (in-list depths)]
[d2 (in-list (cdr depths))]
[d3 (in-list (cddr depths))])
(+ d1 d2 d3)))
(check-equal? (length (positive-deltas (trios depths))) 1130)