How to work Towers of Hanoi code in typescript?

Viewed 43

Here I was able to replicate a python version to typescript of Towers of Hanoi after fixing some errors I was not able to run it, I tried every option to switch some of the code but it still doesn't run. A little guide of what went wrong of my Towers of Hanoi code. Here's the code.

let A = [1, 2, 3];
let B = [];
let C = [];

function move(n, source, auxiliary, target) {
  if (n > 0) {
      move(n, source, target, auxiliary)
      target.append(source.pop());
      console.log(A);
      console.log(B);
      console.log(C);
      console.log('##############', n);
      move(n - 1, auxiliary, source, target);
  }
}

move(3, A, B, C);

Original Python code: Towers of Hanoi

A = [3, 2, 1]
B = []
C = []

def move(n, source, target, auxiliary):
    if n > 0:
    move(n - 1, source, auxiliary, target)
    target.append(source.pop())
    print(A, B, C, '##############', sep='\n')
    move(n - 1, auxiliary, target, source)
    
    move(3, A, C, B)
0 Answers
Related