Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hanoi(n){
- const path = []
- function move(start=1,go=3, depth=n){
- if(depth===1) return path.push([start,go])
- else {
- const other = 6-(start+go)
- move(start, other, depth-1)
- move(start, go , 1)
- move(other, go, depth-1)
- }
- }
- move(1,3,n);
- return path;
- }
Add Comment
Please, Sign In to add comment