//CODING of TOH function in javascript
//original content of arrays A, B and C
A=['A',4,3,2,1];
B=['B'];
C=['C'];
globi=0;
function toh(n,A,B,C)
{
// Moving n disks form A to B via C
if (n<=1) return;
toh(n-1,A,C,B);
globi++;
$('#out').append("<pre>"+globi+" Moving "+A[A.length-1]+" from "+A[0]+" to "+B[0]+"</pre>")
B.push(A.pop());
toh(n-1,C,B,A);
}
#### CODING OF TOH function and full program in PYTHON
# original contents of lists A, B, C
# zeroth element is the label of array itself will not be moved to other lists
A=['A',4, 3,2,1]
B=['B']
C=['C']
i=0
def toh(n,A,B,C):
"""
Moving n disks from A to B via C
"""
global i
if n<=1:
return
toh(n-1,A,C,B)
k=A.pop()
B.append(k)
i+=1
print(f"{i} moved {k} from {A[0]} to {B[0]}")
toh (n-1,C,B,A)
## calling convention
# move ndisks from A to B via C
toh(len(A),A,B,C)
print("Moving A to B via C")
print(A)
print(B)
print(C)