diff options
| author | Mistivia <i@mistivia.com> | 2024-04-19 19:42:12 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-04-19 19:42:12 +0800 |
| commit | 79b3527eed6be5307466366380025becfd709f85 (patch) | |
| tree | 190cda5d89c4cc03bdb1cabdc427a694eb335bba | |
| parent | fedd584842f08b6f3c91354db4287d4c333963b5 (diff) | |
solve day 15 part 1
| -rw-r--r-- | 15/1.rkt | 19 |
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 |
