mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-21 20:47:10 +08:00
Added Whitespace and Docstring (#924)
* Added Whitespace and Docstring I modified the file to make Pylint happier and make the code more readable. * Beautified Code and Added Docstring I modified the file to make Pylint happier and make the code more readable. * Added DOCSTRINGS, Wikipedia link, and whitespace I added DOCSTRINGS and whitespace to make the code more readable and understandable. * Improved Formatting * Wrapped comments * Fixed spelling error for `movement` variable * Added DOCSTRINGs * Improved Formatting * Corrected whitespace to improve readability. * Added docstrings. * Made comments fit inside an 80 column layout.
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
"""Tower of Hanoi."""
|
||||
|
||||
# @author willx75
|
||||
# Tower of Hanoi recursion game algorithm is a game, it consists of three rods and a number of disks of different sizes, which can slide onto any rod
|
||||
# Tower of Hanoi recursion game algorithm is a game, it consists of three rods
|
||||
# and a number of disks of different sizes, which can slide onto any rod
|
||||
|
||||
import logging
|
||||
|
||||
@ -7,18 +10,20 @@ log = logging.getLogger()
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
def Tower_Of_Hanoi(n, source, dest, by, mouvement):
|
||||
def Tower_Of_Hanoi(n, source, dest, by, movement):
|
||||
"""Tower of Hanoi - Move plates to different rods."""
|
||||
if n == 0:
|
||||
return n
|
||||
elif n == 1:
|
||||
mouvement += 1
|
||||
# no print statement (you could make it an optional flag for printing logs)
|
||||
movement += 1
|
||||
# no print statement
|
||||
# (you could make it an optional flag for printing logs)
|
||||
logging.debug('Move the plate from', source, 'to', dest)
|
||||
return mouvement
|
||||
return movement
|
||||
else:
|
||||
|
||||
mouvement = mouvement + Tower_Of_Hanoi(n-1, source, by, dest, 0)
|
||||
movement = movement + Tower_Of_Hanoi(n - 1, source, by, dest, 0)
|
||||
logging.debug('Move the plate from', source, 'to', dest)
|
||||
|
||||
mouvement = mouvement + 1 + Tower_Of_Hanoi(n-1, by, dest, source, 0)
|
||||
return mouvement
|
||||
movement = movement + 1 + Tower_Of_Hanoi(n - 1, by, dest, source, 0)
|
||||
return movement
|
||||
|
Reference in New Issue
Block a user