Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Perfect-shuffle/EchoLisp/perfect-shuffle-1.l
Normal file
19
Task/Perfect-shuffle/EchoLisp/perfect-shuffle-1.l
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
;; shuffler : a permutation vector which interleaves both halves of deck
|
||||
(define (make-shuffler n)
|
||||
(let ((s (make-vector n)))
|
||||
(for ((i (in-range 0 n 2))) (vector-set! s i (/ i 2)))
|
||||
(for ((i (in-range 0 n 2))) (vector-set! s (1+ i) (+ (/ n 2) (vector-ref s i))))
|
||||
s))
|
||||
|
||||
;; output : (n . # of shuffles needed to go back)
|
||||
(define (magic-shuffle n)
|
||||
(when (odd? n) (error "magic-shuffle:odd input" n))
|
||||
(let [(deck (list->vector (iota n))) ;; (0 1 ... n-1)
|
||||
(dock (list->vector (iota n))) ;; keep trace or init deck
|
||||
(shuffler (make-shuffler n))]
|
||||
|
||||
(cons n (1+
|
||||
(for/sum ((i Infinity)) ; (in-naturals missing in EchoLisp v2.9)
|
||||
(vector-permute! deck shuffler) ;; permutes in place
|
||||
#:break (eqv? deck dock) ;; compare to first
|
||||
1)))))
|
||||
12
Task/Perfect-shuffle/EchoLisp/perfect-shuffle-2.l
Normal file
12
Task/Perfect-shuffle/EchoLisp/perfect-shuffle-2.l
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
map magic-shuffle '(8 24 52 100 1020 1024 10000))
|
||||
→ ((8 . 3) (24 . 11) (52 . 8) (100 . 30) (1020 . 1018) (1024 . 10) (10000 . 300))
|
||||
|
||||
;; Let's look in the On-line Encyclopedia of Integer Sequences
|
||||
;; Given a list of numbers, the (oeis ...) function looks for a sequence
|
||||
|
||||
(lib 'web)
|
||||
Lib: web.lib loaded.
|
||||
map magic-shuffle (range 2 18 2))
|
||||
→ ((2 . 1) (4 . 2) (6 . 4) (8 . 3) (10 . 6) (12 . 10) (14 . 12) (16 . 4))
|
||||
(oeis '(1 2 4 3 6 10 12 4))
|
||||
→ Sequence A002326 found
|
||||
Loading…
Add table
Add a link
Reference in a new issue