ó
!ÜôPc           @   s²  d  d l  Z  d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d  „  Z d! „  Z  d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 g Z! i i d8 d8 6d9 d: 6d8 d; 6d< d= 6d= d9 6d: d< 6d8 d> 6d9 d? 6d8 d@ 6d< dA 6d= dB 6d: dC 6d8 dD 6d< dE 6d8 dF 6d9 dG 6d: dH 6d= dI 6d8 dJ 6d; dK 6d8 dL 6d; dM 6d; dN 6d; dO 6d8 6i d< d8 6d: d: 6d9 d; 6d: d= 6d8 d9 6d; d< 6d< d> 6d: d? 6d9 d@ 6d: dA 6d8 dB 6d; dC 6d9 dD 6d: dE 6d< dF 6d: dG 6d; dH 6d8 dI 6d= dJ 6d: dK 6d= dL 6d: dM 6d= dN 6d= dO 6d: 6i d; d8 6d< d: 6d; d; 6d9 d= 6d: d9 6d= d< 6d; d> 6d< d? 6d; d@ 6d9 dA 6d: dB 6d= dC 6d; dD 6d9 dE 6d; dF 6d< dG 6d= dH 6d: dI 6d; dJ 6d8 dK 6d; dL 6d8 dM 6d8 dN 6d8 dO 6d; 6i d9 d8 6d= d: 6d< d; 6d= d= 6d; d9 6d8 d< 6d9 d> 6d= d? 6d< d@ 6d= dA 6d; dB 6d8 dC 6d< dD 6d= dE 6d9 dF 6d= dG 6d8 dH 6d; dI 6d: dJ 6d= dK 6d: dL 6d= dM 6d: dN 6d: dO 6d= 6i d: d8 6d; d: 6d= d; 6d8 d= 6d9 d9 6d9 d< 6d: d> 6d; d? 6d= d@ 6d8 dA 6d9 dB 6d9 dC 6d= dD 6d8 dE 6d: dF 6d; dG 6d9 dH 6d9 dI 6d< dJ 6d< dK 6d< dL 6d< dM 6d9 dN 6d: dO 6d9 6i d= d8 6d8 d: 6d: d; 6d; d= 6d< d9 6d< d< 6d= d> 6d8 d? 6d: d@ 6d; dA 6d< dB 6d< dC 6d: dD 6d; dE 6d= dF 6d8 dG 6d< dH 6d< dI 6d9 dJ 6d9 dK 6d9 dL 6d9 dM 6d< dN 6d< dO 6d< 6Z" i dD d> 6dE d? 6dF d@ 6dG dA 6dH dB 6dI dC 6d> dD 6d? dE 6d@ dF 6dA dG 6dB dH 6dC dI 6dJ dJ 6dK dK 6dL dL 6dM dM 6dN dN 6dO dO 6dD d8 6dE d: 6dF d; 6dG d= 6dH d9 6dI d< 6d8 dD 6d: dE 6d; dF 6d= dG 6d9 dH 6d< dI 6Z# dP d# dQ d% d& dR d( dS dT dU dV dW dX dY dZ d[ d\ d] d^ d_ g Z$ d S(`   iÿÿÿÿNc         C   s8   g  } x! |  D] } | j  t | ƒ ƒ q W| j ƒ  | S(   N(   t   appendt   invert_movet   reverse(   t   proct   resultt   move(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt   invert_moves   s
    
c         C   s   t  |  S(   N(   t   invert_move_table(   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR   &   s    c         C   s   |  | S(   N(    (   t   movest   power(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt   power_of_sequence)   s    c         C   s   |  | t  |  ƒ S(   s3   Returns the conjugate of A by B, i.e. A * B * A^-1.(   R   (   t   proc1t   proc2(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt	   conjugate,   s    c         C   s   |  | t  |  ƒ t  | ƒ S(   sI   Returns the commutator of A and B, i.e. [A, B], i.e. A * B * A^-1 * B^-1.(   R   (   R   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt
   commutator0   s    c         C   s   x |  D]
 } | Gq WHd  S(   N(    (   R   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt   print_moves7   s    c         C   s+   t  |  ƒ } x | D] } t | ƒ q Wd  S(   N(   t   cycle_decompositiont   print_cycle(   R   t   cyclest   cycle(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt   print_cycle_decomposition<   s    c         C   s   x |  D]
 } | Gq WHd  S(   N(    (   R   t   element(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR   A   s    c         C   s7   t  |  ƒ } x$ | D] } x | D]
 } | Gq  WHq Wd  S(   N(   t   images_of_all_pieces(   R   t   pairst   pairR   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt   print_imagesF   s
    c         C   sL   t  |  ƒ d GHt |  ƒ d GHt |  ƒ d GHt |  ƒ d GHt |  ƒ GHHd  S(   Ns   -- Sequence is:s   -- Image is:s   -- Cycle decomposition is:s   -- Order is:(   t   validate_movesR   R   R   t   order(   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt
   tell_aboutN   s    



c         C   sð   g  } d } t  |  ƒ } xÑ | | k  rë |  | } | d | k  rÑ |  | d d k rp | d 7} | |  | 7} qÑ |  | d d k rŸ | d 7} | |  | 7} qÑ |  | d d k rÑ | d 7} | |  | 7} qÑ n  | j | ƒ | d 7} q W| S(   Ni    i   t   +t   -t   2(   t   lenR    (   t   packedt   unpackedt   idxt   ellR   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt   rube_unpack]   s$    



c         C   sÃ   x¼ |  D]´ } t  } t | ƒ } | d k rG | d d k rŽ t } qŽ nG | d k rˆ | d d k rl t } n  | d d k rŽ t } qŽ n t } | s t j d | |  f IJt j d ƒ q q Wd  S(   Ni   i    t   FRBLUDfrbludi   s   +-2s%   Malformed move "%s" in sequence "%s".(   t   TrueR    t   Falset   syst   stderrt   exit(   R   R   t   okR$   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR   r   s     	
c         C   s   t  |  t ƒ S(   N(   t   images_of_piecest   list_of_all_pieces(   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR   †   s    c   	      C   s¬   t  |  | ƒ } g  } t | ƒ } x„ t d | ƒ D]s } | | } | | } t | | ƒ rŽ t | | ƒ } | g  k r¤ | j | | g ƒ q¤ q1 | j | d | g ƒ q1 W| S(   Ni    s   ->(   t   moves_on_piecesR    t   ranget   piece_equalt   sign_of_rotationR    (	   R   t   piecest   imagesR   t   nt   it   piecet   imaget   sign(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR-   ‰   s    

c         C   s   t  t |  t ƒ ƒ S(   s   Given a list of Rubik's Cube pieces and a list of moves, return the cycle
	decomposition of the moves, omitting trivial cycles.(   t   delete_1_cyclest   find_cyclesR.   (   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR   ™   s    c         C   s   t  t t |  ƒ ƒ ƒ S(   N(   t	   multi_lcmt   cycle_lengthsR   (   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR   Ÿ   s    c         C   s*   d } x |  D] } t  | | ƒ } q W| S(   Ni   (   t   lcm2(   t   listR   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR<   £   s    c         C   s   |  | t  |  | ƒ S(   N(   t   gcd2(   t   at   b(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR>   ª   s    c         C   s"   x | r | |  | }  } q W|  S(   N(    (   RA   RB   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR@   ®   s    	c         C   s.   g  } x! |  D] } | j  t | ƒ ƒ q W| S(   N(   R    t   cycle_length(   R   t   lengthsR   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR=   ´   s    c         C   sk   |  d d k s  |  d d k r] t  |  d ƒ d k rH d t  |  ƒ d Sd t  |  ƒ d Sn
 t  |  ƒ Sd  S(   NiÿÿÿÿR   R   i    i   i   i   (   R    (   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyRC   »   s
     c         C   s=   g  } x0 |  D]( } t  | ƒ d k r | j | ƒ q q W| S(   Ni   (   R    R    (   R   t   non_trivial_cyclesR   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR:   Å   s
    c         C   sC   g  } x6 | D]. } t  | | ƒ s | j t |  | ƒ ƒ q q W| S(   N(   t   in_cycle_listR    t
   find_cycle(   R   R3   R   R7   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR;   Í   s
    c         C   s9   x2 | D]* } x! | D] } t  |  | ƒ r t Sq Wq Wt S(   N(   R1   R'   R(   (   R7   R   R   t   cycle_piece(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyRF   Õ   s
    c         C   sa   | g } t  |  | ƒ } x/ t | | ƒ sI | j | ƒ t  |  | ƒ } q W| t | | ƒ 7} | S(   N(   t   moves_on_pieceR1   R    R2   (   R   R7   R   t   next(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyRG   Ý   s    	c         C   s“   |  | k r g  St  |  | ƒ s# g  St |  ƒ d k r< d g S|  t k rm |  d | d k rc d g Sd g Sn" |  d | d k rˆ d g Sd g Sd  S(   Ni   R   i   i    R   (   R1   R    t   clockwise_orient_list(   t   orient_1t   orient_2(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR2   ç   s    
c         C   s1   g  } x$ | D] } | j  t |  | ƒ ƒ q W| S(   N(   R    RI   (   R   R3   R   R7   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR/     s    c         C   st   | } t  | ƒ d k r; x  |  D] } t | | ƒ } q Wn  t  | ƒ d k rp x  |  D] } t | | ƒ } qT Wn  | S(   Ni   i   (   R    t   move_on_corner_piecet   move_on_edge_piece(   R   R7   R   R   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyRI   	  s    c         C   s{   | d } | d } | d } |  d } | | k sL | | k sL | | k rs t  |  | ƒ t  |  | ƒ t  |  | ƒ S| Sd  S(   Ni    i   i   (   t   move_on_face(   R   t   cornert   ps0t   ps1t   ps2t   face(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyRN     s    



$'c         C   sX   | d } | d } |  d } | | k s6 | | k rP t  |  | ƒ t  |  | ƒ S| Sd  S(   Ni    i   (   RP   (   R   t   edgeRR   RS   RU   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyRO   2  s    


c         C   s   t  | |  S(   N(   t   move_on_face_table(   R   RU   (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyRP   J  s    c   
      C   s  t  |  ƒ } t  | ƒ } | | k r( t S| d k rg|  d } |  d } |  d } | d } | d } | d }	 | | k r˜ | | k r˜ | |	 k r˜ t S| | k rÀ | |	 k rÀ | | k rÀ t S| | k rè | | k rè | |	 k rè t S| | k r| |	 k r| | k rt S| |	 k r8| | k r8| | k r8t S| |	 k r`| | k r`| | k r`t St Sn™ | d k rÚ|  d } |  d } | d } | d } | | k r·| | k r·t S| | k rÓ| | k rÓt St Sn& t j d I|  I| IJt j d ƒ d S(   sè  The names of three adjacent faces provide the name of a corner piece;
	the names of two adjacent faces provide the name of an edge piece.
	However, a corner's three faces may be combined in any of six (3!) ways, e.g.
	URF, UFR, FRU, FUR, RFU, and RUF; and an edge's two faces may be combined
	in one of two (2!) ways, e.g. UF and FU.

	This function sees if two representations refer to the same piece.
	E.g. UFR is the same as FRU; UFR is not the same as UFL; UFR is not the
	same as UF.i   i    i   i   s!   piece_equal:  unrecognized input:N(   R    R(   R'   R)   R*   R+   (
   t   piece_1t   piece_2t   length_1t   length_2t   p11t   p12t   p13t   p21t   p22t   p23(    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyR1   N  sJ    





$$$$$$



t   URFt   UFLt   ULBt   UBRt   DFRt   DRBt   DBLt   DLFRFUt   FLUt   LBUt   BRUt   FRDt   RBDt   BLDt   LFDFURt   LUFt   BULt   RUBt   RDFt   BDRt   LDBt   FDLt   Ft   Ut   Rt   Bt   Dt   Ls   F+s   R+s   B+s   L+s   U+s   D+s   F-s   R-s   B-s   L-s   U-s   D-t   F2t   R2t   B2t   L2t   U2t   D2t   UFRt   UBLt   DFLt   DBRt   UFt   ULt   UBt   URt   FRt   FLt   BLt   BRt   DFt   DLt   DBt   DR(%   R)   R   R   R
   R   R   R   R   R   R   R   R%   R   R   R-   R   R   R<   R>   R@   R=   RC   R:   R;   RF   RG   R2   R/   RI   RN   RO   RP   R1   RK   RW   R   R.   (    (    (    sS   /homepages/25/d321765456/htdocs/pub_http_internet/grad-school/rube/python/rube_m.pyt   <module>   s”   																					
				
							G***.***.***.***.***.***1)****-