| Server IP : 121.121.20.254 / Your IP : 216.73.217.141 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Python315/Lib/turtledemo/__pycache__/ |
Upload File : |
R
>lqj� c � � Q s ] QH3 Q Q\2 s Q Q\2 sQ sQ sQ s\ Q 6X c \ 2 s
\ \
2 \ 2 P! P! )
aN turtledemo/minimal_hanoi.py
A minimal 'Towers of Hanoi' animation:
A tower of 6 discs is transferred from the
left to the right peg.
An imho quite elegant and concise
implementation using a tower class, which
is derived from the built-in type list.
Discs are turtles with shape "square", but
stretched to rectangles by shapesize()
)�*c �( ` � \ sQ s]s n Q sQsU sP! )�Discc � � [ O U Q P
Q5 U O 2 U O QUQ* ]2 U O UQ* ] ]UQ* *
2 U O 2 P! )�square)�shape�visibleg �?g @)�Turtle�__init__�pu� shapesize� fillcolor�st)�self�ns &&�-C:\Python315\\Lib\turtledemo\minimal_hanoi.pyr �
Disc.__init__ sV � �����H�e��<���� ����s�A�c�E�1�%����q��t�Q��!�B�$��'���� � � )�__name__�
__module__�__qualname__�__firstlineno__r �__static_attributes__�__classdictcell__��
__classdict__s @r r r s �� � �� r r c �8 ` � \ sQ s]s n QsQ sQ sQ sQsU s P! )�Towerz-Hanoi tower, a subclass of built-in type listc � � Vm P! )z-create an empty tower. x is x-position of peg��x)r r s &&r r �Tower.__init__ s � ��r c � � UO U O 2 UO Q]"[ U 2 * * 2 U O U2 P! )� ij���)�setxr �sety�len�append�r �ds &&r �push�
Tower.push s5 � � ���t�v�v�� ���t�B�s�4�y�L� �!����A�r c �T � [ O U 2 oUO ]�2 U! )r# )�list�popr% r( s & r r. � Tower.pop! s � ��H�H�T�N�� ���s���r r )
r r r r �__doc__r r* r. r r r s @r r r s �� � �3���� r r c � � U ] 6� cJ [ U ]*
VU2 UO UO 2 2 [ U ]*
V!U2 P! P! )� )�hanoir* r. )r �from_�with_�to_s &&&&r r3 r3 &