Skip to content

Instantly share code, notes, and snippets.

@enif-lee
Created January 5, 2017 11:46
Show Gist options
  • Save enif-lee/aaa237253c5e4fa4a9cc172c4d1a538d to your computer and use it in GitHub Desktop.
Save enif-lee/aaa237253c5e4fa4a9cc172c4d1a538d to your computer and use it in GitHub Desktop.
void move(int from, int to){
printf("\nMove from %d to %d", from, to);
}
// n개의 원반을 from 에서 by를 거쳐 to로 옮긴다.
void hanoi(int n, int from, int by, int to){
if (n == 1)
move(from, to);
else{
hanoi(n - 1, from, to, by); // 1번 N-1개의 원반을 기둥3을 거쳐 2로 옮긴다.
move(from, to); // 2번 기둥 1에서 1개의 원반을 기둥 3으롱 롬긴다.
hanoi(n - 1, by, from, to); // 3번 기둥 2에서 N-1개의 원반을 기둥 3으로 옮긴다.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment