ó
ò‰|Pc           @   sI   d  Z  e d „ Z d „  Z e d k rE d Z d e e e ƒ f GHn  d S(   s#  
This program explores the non-randomness of the traditional 'faro'
method of card shuffling.  No matter how many cards there are in a
deck, there is always a finite number of faro shuffles that will
restore their original order.  (Of course, a faro shuffle is very hard
to do in practice!)
c         C   sš   t  |  ƒ } | d g } | r\ |  | d  | d | d d … <|  | d | d | d … <n: |  | d | d | d d … <|  | d  | d | d … <| S(   s  
    performs a 'faro' or 'perfect' shuffle

    `oldDeck` (a sequence) is the original deck.  The shuffled deck is
    returned.  Iff `outShuffle` is True, it does an 'out' shuffle (top
    and bottom cards preserved).  If it is False, it does an 'in'
    shuffle.
    i    i   i   (   t   len(   t   oldDeckt
   outShufflet   nt   newDeck(    (    sD   /home/bobl/Dropbox/cpts481/u14_testing/demos/4_unittest_faro/faro.pyt   faroShuffle	   s    
c         C   se   t  t |  ƒ ƒ } | } d } x@ t r` | GHt | ƒ } | d 7} | | k rW | GH| S| } q! Wd S(   sŸ   
    counts the number of faro shuffles required to restore a deck

    `nCards` is the number of cards in the deck.  It must be an even
    positive int.
    i    i   N(   t   listt   ranget   TrueR   (   t   nCardst   originalDeckt   currentDeckt   shuffleCountt   shuffledDeck(    (    sD   /home/bobl/Dropbox/cpts481/u14_testing/demos/4_unittest_faro/faro.pyt   countShuffles   s    	
t   __main__i4   sF   The ordering of a deck of %d cards is restored after %d faro shuffles.N(   t   __doc__R   R   R   t   __name__R	   (    (    (    sD   /home/bobl/Dropbox/cpts481/u14_testing/demos/4_unittest_faro/faro.pyt   <module>   s   	