Skip to content

Instantly share code, notes, and snippets.

@shilch
Created February 10, 2017 15:51
Show Gist options
  • Save shilch/7805079efe48a1b56b709bc06a266ba1 to your computer and use it in GitHub Desktop.
Save shilch/7805079efe48a1b56b709bc06a266ba1 to your computer and use it in GitHub Desktop.
Tower of Hanoi
// algorithm
let h=(n,a='A',b='B',c='C')=>n===1?console.log('%s -> %s',a,c):h(n-1,a,c,b)||h(1,a,b,c)||h(n-1,b,a,c);
// usage
h(3);
// prints:
// A -> C
// A -> B
// C -> B
// A -> C
// B -> A
// B -> C
// A -> C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment