From 96254947699986c59f0dc63d69fd4b76bd3ed43e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Jul 2026 19:08:08 +0200 Subject: Initial commit --- 01_introductory_problems/tower_of_hanoi_2165.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 01_introductory_problems/tower_of_hanoi_2165.cpp (limited to '01_introductory_problems/tower_of_hanoi_2165.cpp') 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 @@ +#include + +void do_hanoi(int n, int l, int m, int r) { + if (n != 0) { + do_hanoi(n-1, l, r, m); + std::cout << l << " " << r << "\n"; + do_hanoi(n-1, m, l, r); + } +} + +int main() { + int n; + std::cin >> n; + + std::cout << (1 << n) - 1 << "\n"; + do_hanoi(n, 1, 2, 3); +} -- cgit v1.3