aboutsummaryrefslogtreecommitdiff
path: root/2021/day1/01b.rkt
blob: 40337a4e19b5aa31e7d822ff761eee8bfd806f1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#lang racket
(require threading)

(define input (file->lines "input"))

(define (map-differing-lengths f . arrs)
  (define minLength (apply min (map length arrs)))
  (define newLists (map (lambda (x) (take x minLength)) arrs))
  (apply map (cons f newLists)))

(define (build-windows xs)
  (map-differing-lengths list xs (cdr xs) (drop xs 2)))

(define (diff-pairs xs)
  (map-differing-lengths - (cdr xs) xs))

(~>> input
    (map string->number)
    (build-windows)
    (map (lambda (x) (apply + x)))
    (diff-pairs)
    (filter positive?)
    (length _))