Skip to content

Instantly share code, notes, and snippets.

@tuket
Created January 18, 2018 23:37
Show Gist options
  • Save tuket/3bb6cfde0573ae8ae2f3dd1e04aeede0 to your computer and use it in GitHub Desktop.
Save tuket/3bb6cfde0573ae8ae2f3dd1e04aeede0 to your computer and use it in GitHub Desktop.
hanoi towers
#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