cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

tower_of_hanoi_2165.cpp (275B)


      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 }