aboutsummaryrefslogtreecommitdiff
path: root/01_introductory_problems/tower_of_hanoi_2165.cpp
blob: 2b83788c7579229b9fc990d1a5d3b62d5d274a10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

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);
}

Generated with cgit - Back to sebastiano.tronto.net