diff options
Diffstat (limited to '2021/day1/01a.rkt')
-rw-r--r-- | 2021/day1/01a.rkt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/2021/day1/01a.rkt b/2021/day1/01a.rkt new file mode 100644 index 0000000..5f3ea26 --- /dev/null +++ b/2021/day1/01a.rkt @@ -0,0 +1,18 @@ +#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 (diff-pairs xs) + (map-differing-lengths - (cdr xs) xs)) + +(~>> input + (map string->number) + (diff-pairs) + (filter positive?) + (length _)) |