Program for Tower of Hanoi | javascript recursive function to solve tower of hanoi puzzle ; Number of disks ; A , B and C are names of rods
function towerOfHanoi ( n , from_rod , to_rod , aux_rod ) { if ( n == 1 ) { document . write ( " " + from_rod + " " + to_rod + " " ) ; return ; } towerOfHanoi ( n - 1 , from_rod , aux_rod , to_rod ) ; document . write ( " " + n + " " + from_rod + " " + to_rod + " " ) ; towerOfHanoi ( n - 1 , aux_rod , to_rod , from_rod ) ; } var n = 4 ; towerOfHanoi ( n , ' ' , ' ' , ' ' ) ;