d22 p1
parent
405ee1eca0
commit
70fbb19f3e
@ -0,0 +1,55 @@
|
||||
#lang br
|
||||
(require racket/file rackunit)
|
||||
|
||||
(define (stack cards)
|
||||
(reverse cards))
|
||||
|
||||
(define (cut n cards)
|
||||
(define-values (head tail)
|
||||
(split-at cards (match n
|
||||
[(? positive?) n]
|
||||
[_ (- (length cards) (abs n))])))
|
||||
(append tail head))
|
||||
|
||||
(define (increment n cards)
|
||||
(define len (length cards))
|
||||
(define vec (make-vector len))
|
||||
(for ([(card idx) (in-indexed cards)])
|
||||
(vector-set! vec (modulo (* idx n) len) card))
|
||||
(vector->list vec))
|
||||
|
||||
(define (run program [deck-size 10])
|
||||
(for/fold ([cards (range deck-size)])
|
||||
([ln (in-list (string-split program "\n"))])
|
||||
(match (string-split ln)
|
||||
[(list "cut" (app string->number num)) (cut num cards)]
|
||||
[(list _ _ "increment" (app string->number num)) (increment num cards)]
|
||||
[_ (stack cards)])))
|
||||
|
||||
(check-equal?
|
||||
(run "deal with increment 7
|
||||
deal into new stack
|
||||
deal into new stack")
|
||||
'(0 3 6 9 2 5 8 1 4 7))
|
||||
|
||||
(check-equal?
|
||||
(run "cut 6
|
||||
deal with increment 7
|
||||
deal into new stack")
|
||||
'(3 0 7 4 1 8 5 2 9 6))
|
||||
|
||||
(check-equal?
|
||||
(run "deal into new stack
|
||||
cut -2
|
||||
deal with increment 7
|
||||
cut 8
|
||||
cut -4
|
||||
deal with increment 7
|
||||
cut 3
|
||||
deal with increment 9
|
||||
deal with increment 3
|
||||
cut -1")
|
||||
'(9 2 5 8 1 4 7 0 3 6))
|
||||
|
||||
;; 1
|
||||
(check-eq? (index-of (run (file->string "22.rktd") 10007) 2019) 4086)
|
@ -0,0 +1,100 @@
|
||||
cut -135
|
||||
deal with increment 38
|
||||
deal into new stack
|
||||
deal with increment 29
|
||||
cut 120
|
||||
deal with increment 30
|
||||
deal into new stack
|
||||
cut -7198
|
||||
deal into new stack
|
||||
deal with increment 59
|
||||
cut -8217
|
||||
deal with increment 75
|
||||
cut 4868
|
||||
deal with increment 29
|
||||
cut 4871
|
||||
deal with increment 2
|
||||
deal into new stack
|
||||
deal with increment 54
|
||||
cut 777
|
||||
deal with increment 40
|
||||
cut -8611
|
||||
deal with increment 3
|
||||
cut -5726
|
||||
deal with increment 57
|
||||
deal into new stack
|
||||
deal with increment 41
|
||||
deal into new stack
|
||||
cut -5027
|
||||
deal with increment 12
|
||||
cut -5883
|
||||
deal with increment 45
|
||||
cut 9989
|
||||
deal with increment 14
|
||||
cut 6535
|
||||
deal with increment 18
|
||||
cut -5544
|
||||
deal with increment 29
|
||||
deal into new stack
|
||||
deal with increment 64
|
||||
deal into new stack
|
||||
deal with increment 41
|
||||
deal into new stack
|
||||
deal with increment 6
|
||||
cut 4752
|
||||
deal with increment 8
|
||||
deal into new stack
|
||||
deal with increment 26
|
||||
cut -6635
|
||||
deal with increment 10
|
||||
deal into new stack
|
||||
cut -3830
|
||||
deal with increment 48
|
||||
deal into new stack
|
||||
deal with increment 39
|
||||
cut -4768
|
||||
deal with increment 65
|
||||
deal into new stack
|
||||
cut -5417
|
||||
deal with increment 15
|
||||
cut -4647
|
||||
deal into new stack
|
||||
cut -3596
|
||||
deal with increment 17
|
||||
cut -3771
|
||||
deal with increment 50
|
||||
cut 1682
|
||||
deal into new stack
|
||||
deal with increment 20
|
||||
deal into new stack
|
||||
deal with increment 22
|
||||
deal into new stack
|
||||
deal with increment 3
|
||||
cut 8780
|
||||
deal with increment 52
|
||||
cut 7478
|
||||
deal with increment 9
|
||||
cut -8313
|
||||
deal into new stack
|
||||
cut 742
|
||||
deal with increment 19
|
||||
cut 9982
|
||||
deal into new stack
|
||||
deal with increment 68
|
||||
cut 9997
|
||||
deal with increment 23
|
||||
cut -240
|
||||
deal with increment 54
|
||||
cut -7643
|
||||
deal into new stack
|
||||
deal with increment 6
|
||||
cut -3493
|
||||
deal with increment 74
|
||||
deal into new stack
|
||||
deal with increment 75
|
||||
deal into new stack
|
||||
deal with increment 40
|
||||
cut 596
|
||||
deal with increment 6
|
||||
cut -4957
|
||||
deal into new stack
|
Reference in New Issue