aboutsummaryrefslogtreecommitdiff
path: root/15/1.rkt
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-04-19 19:42:12 +0800
committerMistivia <i@mistivia.com>2024-04-19 19:42:12 +0800
commit79b3527eed6be5307466366380025becfd709f85 (patch)
tree190cda5d89c4cc03bdb1cabdc427a694eb335bba /15/1.rkt
parentfedd584842f08b6f3c91354db4287d4c333963b5 (diff)
solve day 15 part 1
Diffstat (limited to '15/1.rkt')
-rw-r--r--15/1.rkt19
1 files changed, 19 insertions, 0 deletions
diff --git a/15/1.rkt b/15/1.rkt
new file mode 100644
index 0000000..448a10e
--- /dev/null
+++ b/15/1.rkt
@@ -0,0 +1,19 @@
+#lang racket
+
+(define line
+ (call-with-input-file "input"
+ (λ (fp) (read-line fp))))
+
+(define strs (string-split line ","))
+
+(define (calc-hash str)
+ (define len (string-length str))
+ (let loop ((i 0) (cur 0))
+ (if (< i len)
+ (let ()
+ (define c (string-ref str i))
+ (define ascii (char->integer c))
+ (loop (+ i 1) (modulo (* 17 (+ cur ascii)) 256)))
+ cur)))
+
+(apply + (map calc-hash strs)) \ No newline at end of file