Returns all movements needed to solve Hanoi Tower problem.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
count |
Number
|
Count of the plates/stones. |
source |
String
|
Number
|
Identifier of the 1st peg. |
intermediate |
String
|
Number
|
Identifier of the 2nd peg. |
goal |
String
|
Number
|
Identifier of the 3rd peg. |
Returns:
Array which contains all the moves required
in order to place all the plates onto the last peg.
Example
var hanoi = require('path-to-algorithms/src/others/hanoi').hanoi;
var movements = hanoi(3, 'a', 'b', 'c');
// Move a to c
// Move a to b
// Move c to b
// Move a to c
// Move b to a
// Move b to c
// Move a to c
movements.forEach(function (move) {
console.log('Move', move[0], 'to', move[1]);
});