<jupyter_start><jupyter_text>What is the Tower of Hanoi? Tower of Hanoi is a puzzle in which there are three rods and three disks(generally). The disks are of different sizes.Tower of Hanoi, mathematical puzzle was invented by the French mathematician <NAME> in the year 1883.The aim is to transfer the disks from one source rod to another target or destination rod.  Rules of solving the Puzzle There are some rules which must not be violated while solving the puzzle. These rules are quite simple unlike the implementation and solution. But worry not, we will get through it.There are three rods. The disks are arranged in the descending order i.e., the largest disk is placed at the bottom and the smallest one on the top. The rules are as follows:-1. Only one disk can be moved among the towers at any given time.2. Only the "top" disk can be removed.3. No large disk can sit over a small disk. ![tower_of_hanoi.jpg](attachment:tower_of_hanoi.jpg)  The number of moves can be calculated using the formula 2^n-1  We need to solve the puzzle in 7 moves from the above formula.Suppose that the leftmost rod is called SOURCE, the rightmost rod is called TARGET and the rod in the middle is referred to as an AUX.*Recursion- It is a technique in which a fuction/method calls itself until a specified condition is met.*  Python Program to solve the Tower of Hanoi puzzle using recursion<jupyter_code>def TOH(ndisks, start, auxiliary, end):  #TOH stands for Tower of Hanoi, this is the recursive function.
    if(ndisks == 1):  
        print('Move disk 1 from rod {} to rod {}'.format(start, end))  
        #The format() method formats the specified values and inserts them inside the string's placeholder i.e., curly braces.
        return
    TOH(ndisks - 1, start, end, auxiliary)  #function calls itself
    print('Move disk {} from rod {} to rod {}'.format(ndisks, start, end))  
    TOH(ndisks - 1, auxiliary, start, end)  
  #Driver code
ndisks = int(input('Enter number of disks: '))
TOH(ndisks, 'A', 'B', 'C')<jupyter_output>Enter number of disks: 3
Move disk 1 from rod A to rod C
Move disk 2 from rod A to rod B
Move disk 1 from rod C to rod B
Move disk 3 from rod A to rod C
Move disk 1 from rod B to rod A
Move disk 2 from rod B to rod C
Move disk 1 from rod A to rod C
{'fraction_non_alphanumeric': 0.06049978079789566, 'fraction_numerical': 0.009644892590968873, 'mean_word_length': 3.8143459915611815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '547739', 'license': 'MIT', 'n_tokens_mistral': 674, 'n_tokens_neox': 617, 'n_words': 376, 'path': 'Python/Tower of Hanoi.ipynb', 'repo_name': 'pragatikesarwani38/winter-of-contributing', 'size': '2288'}