aboutsummaryrefslogtreecommitdiff
path: root/01/1.scm
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-12-02 00:02:09 +0800
committerMistivia <i@mistivia.com>2024-12-02 00:02:09 +0800
commite1e6b569d00e88ce313240c680a5111dbd159648 (patch)
tree47be80d348a115388132278bc6ecc85dd59e3cdf /01/1.scm
day 1
Diffstat (limited to '01/1.scm')
-rw-r--r--01/1.scm27
1 files changed, 27 insertions, 0 deletions
diff --git a/01/1.scm b/01/1.scm
new file mode 100644
index 0000000..fd9f607
--- /dev/null
+++ b/01/1.scm
@@ -0,0 +1,27 @@
+(import (chicken string))
+(import (chicken io))
+(import (chicken sort))
+
+(define input
+ (with-input-from-file "input"
+ (lambda ()
+ (let loop ((ret '()))
+ (let ((line (read-line)))
+ (if (eof-object? line)
+ (reverse ret)
+ (loop (cons line ret))))))))
+
+(set! input (map string-split input))
+
+(define first-lst (map string->number (map car input)))
+(define second-lst (map string->number (map cadr input)))
+
+(set! first-lst (sort first-lst <))
+(set! second-lst (sort second-lst <))
+
+(define diff (map abs (map - first-lst second-lst)))
+
+(define result (apply + diff))
+
+(display result)
+(newline)