diff options
author | JJ | 2025-01-02 02:11:37 +0000 |
---|---|---|
committer | JJ | 2025-01-02 02:11:37 +0000 |
commit | 830b65d349ec148df049522a1875a8e3d5ce7697 (patch) | |
tree | a73509543bce34fc95ae1f4e3b6a85be11fa2dad /2024/racket | |
parent | 0e8d6bbf3e55e7506e1e92b5292833b1f3907d06 (diff) |
january adventing... omg...
Diffstat (limited to '2024/racket')
-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))) |