summaryrefslogtreecommitdiff
path: root/algorithms/hanoi.cc
diff options
context:
space:
mode:
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;
+}