From cf3a29feb5887344b6633ead1b4b6d5657a15a4b Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 15 Jun 2014 03:24:33 +0200 Subject: old stuff: algorithms --- algorithms/hanoi.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 algorithms/hanoi.cc (limited to 'algorithms/hanoi.cc') diff --git a/algorithms/hanoi.cc b/algorithms/hanoi.cc new file mode 100644 index 0000000..e97b261 --- /dev/null +++ b/algorithms/hanoi.cc @@ -0,0 +1,41 @@ +#include + +#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; +} -- cgit v1.2.3