|
|
|
@ -9,7 +9,7 @@
|
|
|
|
|
|
|
|
|
|
(define-macro (mb NUM-STR)
|
|
|
|
|
#'(#%module-begin
|
|
|
|
|
(displayln (solve (string->number NUM-STR) #f))
|
|
|
|
|
#;(displayln (solve (string->number NUM-STR) #f))
|
|
|
|
|
(displayln (solve (string->number NUM-STR) #t))))
|
|
|
|
|
|
|
|
|
|
(define (idx-after vec x)
|
|
|
|
@ -17,7 +17,7 @@
|
|
|
|
|
(for/first ([idx (in-range (modulo (add1 x) (vector-length vec)) (vector-length vec))]
|
|
|
|
|
#:when (vector-ref vec idx))
|
|
|
|
|
idx)
|
|
|
|
|
(idx-after vec 0)))
|
|
|
|
|
(idx-after vec -1)))
|
|
|
|
|
|
|
|
|
|
(define (solve num [circle? #f])
|
|
|
|
|
(define elves (make-vector num #t))
|
|
|
|
@ -26,7 +26,7 @@
|
|
|
|
|
[(= elves-left 2) (add1 taker)]
|
|
|
|
|
[else
|
|
|
|
|
(define giver (for/fold ([elf taker])
|
|
|
|
|
([i (in-range (if circle? (floor (/ num 2)) 1))])
|
|
|
|
|
([i (in-range (if circle? (floor (/ elves-left 2)) 1))])
|
|
|
|
|
(idx-after elves elf)))
|
|
|
|
|
(vector-set! elves giver #f)
|
|
|
|
|
(loop (idx-after elves taker) (sub1 elves-left))])))
|
|
|
|
|