Tower of Hanoi
Description:
Your Task
Implement a solution for the Tower of Hanoi.
Tower of Hanoi in a nutshell
You begin with an array of arrays of length 3, and the first array with an x amount of floors (ascending order)
var next_step;
var tower = [[1, 2, 3, , x], [], []]
You can move one value at a time
next_step = [[2, 3, , x], [], [1]]
You cannot move a number on top of a smaller one
next_step = [[3, , x], [], [2, 1]] // This cannot happen since 2 is bigger than 1
The aim of the game is to move every value from the left-most array one by one to the right-most one, following the rules described above and (for this kata) the initial structure of the implementation explained below.
Implementation
For this Kata you will create a function hanoi that takes as a parameter the amount of disks the tower is going to have
var hanoi = function(disks) { }
This function will posses a nextStep function in which you'll work the logic to move each individual disk one call at a time
var tower = hanoi(3)
tower.nextStep() // [[2, 3], [], [1]]
tower.nextStep() // [[3], [2], [1]]
And once it arrives to the last step, if called again it should throw an error
var tower = hanoi(3)
/* Magic */
tower.nextStep() // [[], [], [1, 2, 3]]
tower.nextStep() // Error ==> Sequence contains no more elements.
More about the Tower of Hanoi
Similar Kata:
Stats:
Created | Mar 12, 2015 |
Published | Mar 12, 2015 |
Warriors Trained | 147 |
Total Skips | 7 |
Total Code Submissions | 128 |
Total Times Completed | 22 |
JavaScript Completions | 22 |
Total Stars | 10 |
% of votes with a positive feedback rating | 100% of 14 |
Total "Very Satisfied" Votes | 14 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 14 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |