diff options
author | Aria <me@aria.rip> | 2023-01-02 21:58:56 +0000 |
---|---|---|
committer | Aria <me@aria.rip> | 2023-01-02 21:58:56 +0000 |
commit | 5eb58ad076f2cd435b11b140820da224b60b73d5 (patch) | |
tree | 2a67939595fbf993ff04f69b9cd3f0aa20827d96 /2021/day1 |
initial commit
Diffstat (limited to '2021/day1')
-rw-r--r-- | 2021/day1/01a.rkt | 18 | ||||
-rw-r--r-- | 2021/day1/01b.rkt | 23 |
2 files changed, 41 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 _)) diff --git a/2021/day1/01b.rkt b/2021/day1/01b.rkt new file mode 100644 index 0000000..40337a4 --- /dev/null +++ b/2021/day1/01b.rkt @@ -0,0 +1,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 _)) |