1
0
Fork 0
This commit is contained in:
Jonathan Chan 2020-12-14 21:46:39 -08:00 committed by Jonathan Chan
parent 2f2945614c
commit 4a858eca81
2 changed files with 22 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
**/*.bak **/*.bak
**/*.rkt~ **/*.rkt~
**/*.txt~ **/*.txt~
**/*.exe
**/compiled/ **/compiled/

21
src/15.rkt Normal file
View File

@ -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))