0.0.2 • Published 7 years ago
hanoi v0.0.2
hanoi
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
Install
npm install hanoi
bower install hanoi
Usage
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
Test
npm test
License
MIT