From 830b65d349ec148df049522a1875a8e3d5ce7697 Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 1 Jan 2025 18:11:37 -0800 Subject: january adventing... omg... --- 2024/racket/day01.rkt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2024/racket/day01.rkt (limited to '2024/racket') 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))) -- cgit v1.2.3-70-g09d2