about | help | code help+videos | done | prefs |
The Tower of Hanoi is a puzzle where there is a stack of disks, each one smaller than the one below it, all placed on one of three rods. The puzzle is to move all the disks from the left rod to the right rod, possibly using the middle rod as necessary. You can only move one disk at a time, onto another rod, but never moving a disk onto a disk that is smaller.
Stack<Integer> left = new Stack<Integer>(); left.addAll(L); Stack<Integer> middle = new Stack<Integer>(); middle.addAll(M); Stack<Integer> right = new Stack<Integer>(); right.addAll(R); towerOfHanoi(1, [1], [], []) → ["1LR"] towerOfHanoi(2, [2, 1], [], []) → ["1LM", "2LR", "1MR"] towerOfHanoi(3, [3, 2, 1], [], []) → ["1LR", "2LM", "1RM", "3LR", "1ML", "2MR", "1LR"] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy