summaryrefslogtreecommitdiff
path: root/algorithms/hanoi.cc
blob: e97b2611e9ca2feeee18de1f6cae916a7d617a2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

#define N 16

using namespace std;


/*
 * 1   _
 * 2  __
 * 3 ___
 *  ____ _____ _____
 *   1     2     3
*/

int i=0;

void
move(int n, int from, int to, int by)
{
	i++;
		
	if (n > 1) {
		move(n-1, from, by, to);
	}
	
	cout << "Bewege Scheibe " << n << " von Pos. \'" << from << "\' nach Pos. \
\'" << to << "\'" << endl;
	
	if (n > 1) {
		move(n-1, by, to, from);
	}
}

int main(void)
{
	move(N, 1, 3, 2);
	cout << "number of moves: " << i << endl;

	return 0;
}