Created
January 18, 2018 23:37
-
-
Save tuket/3bb6cfde0573ae8ae2f3dd1e04aeede0 to your computer and use it in GitHub Desktop.
hanoi towers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// there are 3 sticks: 0, 1, 2 | |
void move(int x, int from, int to) | |
{ | |
if(x == 1) printf("%d->%d\n", from, to); | |
else | |
{ | |
int other = 3-from-to; | |
move(x-1, from, other); | |
move(1, from, to); | |
move(x-1, other, to); | |
} | |
} | |
int main() | |
{ | |
move(5, 0, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment