Created
May 8, 2023 18:56
-
-
Save sjdonado/f4760799c6eb2af9d9d0e12413aa0eab to your computer and use it in GitHub Desktop.
Tower of Hanoi in P5.js + WASM - Dev.to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recursiveHanoi(A, C, B, n){ | |
if (n == 1) { | |
moves.push(A + ":" + C); | |
} else { | |
recursiveHanoi(A, B, C, n - 1); | |
moves.push(A + ":" + C); | |
recursiveHanoi(B, C, A, n - 1); | |
} | |
} | |
function generateHanoiArray(disksNumber) { | |
var moves = []; | |
recursiveHanoi(0, 2, 1, disksNumber); | |
return moves; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment