diff --git a/.gitignore b/.gitignore index 072f362..f8acb17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ **/*.bak **/*.rkt~ **/*.txt~ +**/*.exe **/compiled/ diff --git a/src/15.rkt b/src/15.rkt new file mode 100644 index 0000000..d283602 --- /dev/null +++ b/src/15.rkt @@ -0,0 +1,21 @@ +#lang curly-fn racket + +(require "../lib.rkt") + +(define input '(5 1 9 18 13 8 0)) + +(define (play end) + (define turns + (make-hash (map cons input (range 1 (add1 (length input)))))) + (let loop ([turn (length input)] [curr (last input)]) + (cond + [(>= turn end) curr] + [(hash-has-key? turns curr) + (let ([next (- turn (hash-ref turns curr))]) + (hash-set! turns curr turn) + (loop (add1 turn) next))] + [else + (hash-set! turns curr turn) + (loop (add1 turn) 0)]))) + +(show-solution (play 2020) (play 30000000))