diff options
| -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 |
