hanoi

0.0.2 • Public • Published

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

Towers of Hanoi alogrithm

source

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

Package Sidebar

Install

npm i hanoi

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • miguelmota