---
title: Towers of Hanoi
id: 5951ed8945deab770972ae56
challengeType: 5
forumTopicId: 302341
---
## Description
towerOfHanoi(4, 'A', 'B', 'C')
. The function should return an array of arrays containing the list of moves, source -> destination.
For example, the array [['A', 'C'], ['B', 'A']]
indicates that the 1st move was to move a disc from stack A to C, and the 2nd move was to move a disc from stack B to A.
## Instructions
towerOfHanoi
is a function.
testString: assert(typeof towerOfHanoi === 'function');
- text: towerOfHanoi(3, ...)
should return 7 moves.
testString: assert(res3.length === 7);
- text: towerOfHanoi(3, 'A', 'B', 'C')
should return [['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B']]
.
testString: assert.deepEqual(towerOfHanoi(3, 'A', 'B', 'C'), res3Moves);
- text: towerOfHanoi(5, "X", "Y", "Z")
10th move should be Y -> X.
testString: assert.deepEqual(res5[9], ['Y', 'X']);
- text: towerOfHanoi(7, 'A', 'B', 'C')
first ten moves are [['A','B'], ['A','C'], ['B','C'], ['A','B'], ['C','A'], ['C','B'], ['A','B'], ['A','C'], ['B','C'], ['B','A']]
testString: assert.deepEqual(towerOfHanoi(7, 'A', 'B', 'C').slice(0, 10), res7First10Moves);
```