summaryrefslogtreecommitdiff
path: root/cpp/hanoi.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/hanoi.cc')
-rw-r--r--cpp/hanoi.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/cpp/hanoi.cc b/cpp/hanoi.cc
new file mode 100644
index 0000000..b401060
--- /dev/null
+++ b/cpp/hanoi.cc
@@ -0,0 +1,29 @@
+// ConsoleApplication1.cpp : definisce il punto di ingresso dell'applicazione console.
+//
+#include "stdafx.h"
+#include <iostream>
+
+using namespace std;
+
+static unsigned long int tot = 0;
+
+void hanoi(int d, int inizio, int fine, int transito)
+{
+ if (d == 1);
+ else {
+ hanoi(d - 1, inizio, transito, fine);
+ hanoi(d - 1, transito, fine, inizio);
+ }
+ tot++;
+}
+
+int main()
+{
+ int dischi;
+ cout << "Numero dischi: ";
+ cin >> dischi;
+
+ hanoi(dischi, 1, 3, 2);
+ cout << "In totale: " << tot << " mosse" << endl;
+ return 0;
+}