summaryrefslogtreecommitdiff
path: root/algorithms/hanoi.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-15 03:24:33 +0200
committerPatrick Simianer <p@simianer.de>2014-06-15 03:24:33 +0200
commitcf3a29feb5887344b6633ead1b4b6d5657a15a4b (patch)
treef1149508f7305a48dba0226699dfafdd68d81969 /algorithms/hanoi.cc
parent5ddc763ab9953eebdaf78af4eb72288d7955b310 (diff)
old stuff: algorithms
Diffstat (limited to 'algorithms/hanoi.cc')
-rw-r--r--algorithms/hanoi.cc41
1 files changed, 41 insertions, 0 deletions
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 <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;
+}