Horje
tower of hanoi Code Example
tower of hanoi
/// find total number of steps 
int towerOfHanoi(int n) {
  /// pow(2,n)-1
  if (n == 0) return 0;
  
  return towerOfHanoi(n - 1) + 1 + towerOfHanoi(n - 1);
}
tower of hanoi
# Recursive Python function to solve tower of hanoi
 
def TowerOfHanoi(n , from_rod, to_rod, aux_rod):
    if n == 0:
        return
    TowerOfHanoi(n-1, from_rod, aux_rod, to_rod)
    print("Move disk",n,"from rod",from_rod,"to rod",to_rod)
    TowerOfHanoi(n-1, aux_rod, to_rod, from_rod)
         
# Driver code
n = 4
TowerOfHanoi(n, 'A', 'C', 'B')
# A, C, B are the name of rods
 
# Contributed By Harshit Agrawal
Tower of Hanoi
def towerOfHanoi(N , source, destination, auxiliary):
	if N==1:
		print("Move disk 1 from source",source,"to destination",destination)
		return
	towerOfHanoi(N-1, source, auxiliary, destination)
	print("Move disk",N,"from source",source,"to destination",destination)
	towerOfHanoi(N-1, auxiliary, destination, source)
		
# Driver code
N = 3
towerOfHanoi(N,'A','B','C')
# A, C, B are the name of rods
Source: favtutor.com




Cpp

Related
c++ vector structure Code Example c++ vector structure Code Example
sum of n natural numbers in c Code Example sum of n natural numbers in c Code Example
c++ write string Code Example c++ write string Code Example
size of set c++ Code Example size of set c++ Code Example
cpp vector structure Code Example cpp vector structure Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12