#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Perfect_shuffle
#

func perfect_shuffle(deck) {
     var mid = deck.len/2;
     [deck.part(mid)].zip.flatten
}

[8, 24, 52, 100].each { |size|

    var deck = size.of { _ };
    var shuffled = deck;

    var n = 0;
    loop {
        ++n;
        shuffled = perfect_shuffle(shuffled);

        shuffled.each_index { |i|
            shuffled[i] == deck[i] || goto :NEXT;
        }

        break;
        @:NEXT;
    }

    printf("%5d cards: %4d\n", size, n);
}
