diff options
Diffstat (limited to '')
| -rw-r--r-- | 01_introductory_problems/tower_of_hanoi_2165.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/01_introductory_problems/tower_of_hanoi_2165.cpp b/01_introductory_problems/tower_of_hanoi_2165.cpp new file mode 100644 index 0000000..2b83788 --- /dev/null +++ b/01_introductory_problems/tower_of_hanoi_2165.cpp | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #include <iostream> | ||
| 2 | |||
| 3 | void do_hanoi(int n, int l, int m, int r) { | ||
| 4 | if (n != 0) { | ||
| 5 | do_hanoi(n-1, l, r, m); | ||
| 6 | std::cout << l << " " << r << "\n"; | ||
| 7 | do_hanoi(n-1, m, l, r); | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | int main() { | ||
| 12 | int n; | ||
| 13 | std::cin >> n; | ||
| 14 | |||
| 15 | std::cout << (1 << n) - 1 << "\n"; | ||
| 16 | do_hanoi(n, 1, 2, 3); | ||
| 17 | } | ||
