The document describes an algorithm for solving the Tower of Hanoi problem with three pegs (source, auxiliary, and destination) by recursively moving disks of decreasing size. A function is defined that takes the number of disks and three peg names as input, and uses recursion and printing statements to iteratively move the disks. The number of disks is prompted as input, and the function is called to output the required moves.
Original Description:
Original Title
Algorithm for Intelligent Systems and Robotics Lab exp 2 500096635
The document describes an algorithm for solving the Tower of Hanoi problem with three pegs (source, auxiliary, and destination) by recursively moving disks of decreasing size. A function is defined that takes the number of disks and three peg names as input, and uses recursion and printing statements to iteratively move the disks. The number of disks is prompted as input, and the function is called to output the required moves.
The document describes an algorithm for solving the Tower of Hanoi problem with three pegs (source, auxiliary, and destination) by recursively moving disks of decreasing size. A function is defined that takes the number of disks and three peg names as input, and uses recursion and printing statements to iteratively move the disks. The number of disks is prompted as input, and the function is called to output the required moves.
Algorithm for Intelligent Systems and Robotics Lab
Experiment -2 Tower of Hanoi Problem
Name – Abhit Yadav
Sap Id – 500096635 Roll no. – R2142211143 Batch – B5 Write a code to find the solution of tower of Hanoi problem with three pegs source, auxiliary and destination where n (no. of disks) is taken as an input from user in python. Input –
if n == 1: print(f"Move disk 1 from {source} to {destination}") return tower_of_hanoi(n - 1, source, destination, auxillary) print(f"Move disk {n} from {source} to {destination}") tower_of_hanoi(n - 1, auxillary, source, destination)