diff options
Diffstat (limited to '2024/racket/day01.rkt')
-rw-r--r-- | 2024/racket/day01.rkt | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/2024/racket/day01.rkt b/2024/racket/day01.rkt new file mode 100644 index 0000000..52aa9cd --- /dev/null +++ b/2024/racket/day01.rkt @@ -0,0 +1,16 @@ +#lang racket + +;; Day 1: Historian Hysteria + +(command-line #:args (filename) +(let* ([input (file->lines filename)] + [l1 (map (λ (x) (string->number (substring x 0 5))) input)] + [l2 (map (λ (x) (string->number (substring x 8 13))) input)]) + +(foldl + (λ (a b acc) (+ acc (abs (- a b)))) + 0 (sort l1 <) (sort l2 <)) + +(foldl + (λ (a acc) (+ acc (* a (count (λ (x) (= x a)) l2)))) + 0 l1))) |