hanoi
Version:
Tower of Hanoi algorithm for finding the smallest number of steps to move the stack.
47 lines (32 loc) • 1.18 kB
Markdown
> Tower of Hanoi algorithm for finding the smallest number of steps to move the stack.
The Towers of Hanoi is a mathematical puzzle whose solution illustrates recursion. There are three pegs which can hold stacks of disks of different diameters. A larger disk may never be stacked on top of a smaller. Starting with `n` disks on one peg, they must be moved to another peg one at a time. — [Wikipedia](https://en.wikipedia.org/wiki/Recursion_(computer_science)#Towers_of_Hanoi)
[](https://en.wikipedia.org/wiki/Tower_of_Hanoi)
<sup>[source](https://en.wikipedia.org/wiki/Tower_of_Hanoi)</sup>
```bash
npm install hanoi
```
```bash
bower install hanoi
```
```javascript
const hanoi = require('hanoi');
console.log(hanoi(0)); // 0
console.log(hanoi(1)); // 1
console.log(hanoi(2)); // 3
console.log(hanoi(3)); // 7
console.log(hanoi(4)); // 15
console.log(hanoi(5)); // 31
console.log(hanoi(6)); // 63
console.log(hanoi(7)); // 127
console.log(hanoi(8)); // 255
console.log(hanoi(9)); // 511
```
```bash
npm test
```
MIT