Innovative Activity Report Format
Innovative Activity Report Format
Theory:
Identify three pegs: source (A), auxiliary (B), and destination (C).Initialize a variable
n to the number of disks to be moved. If n is 1, move the top disk from the source peg
(A) to the destination peg (C) directly. Otherwise, follow these steps recursively: a.
Move the top n-1 disks from the source peg (A) to the auxiliary peg (B) using the
destination peg (C) as a temporary peg. b. Move the remaining disk from the source
peg (A) to the destination peg (C). c. Move the n-1 disks from the auxiliary peg (B) to
the destination peg (C) using the source peg (A) as a temporary peg. Repeat the above
steps until all disks are moved from the source peg (A) to the destination peg (C).The
algorithm follows the principles of divide and conquer, moving smaller subproblems
first and leveraging recursion to solve larger instances of the problem. This algorithm
ensures that the Tower of Hanoi puzzle is solved efficiently with the least number of
moves while adhering to the rules of the game.
Code:
#include <stdio.h>
void towerOfHanoi(int n, char source, char auxiliary, char destination)
{
if (n == 1)
{
printf("Move disk 1 from %c to %c\n", source, destination);
return;
}
towerOfHanoi(n - 1, source, destination, auxiliary);
printf("Move disk %d from %c to %c\n", n, source, destination);
towerOfHanoi(n - 1, auxiliary, source, destination);
}
int main()
{
int n;
printf("Enter the number of disks: ");
scanf("%d", &n);
towerOfHanoi(n, 'A', 'B', 'C');
return 0;
}
Output:
Conclusion:
The Tower of Hanoi is a simple mathematical puzzle often employed for the assessment of problem-
solving and in the evaluation of frontal lobe deficits. The task allows researchers to observe the
participant's moves and problem-solving ability, which reflect the individual's ability to solve simple
real-world problems