summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-01-31 22:29:41 +0100
committerGitHub <noreply@github.com>2017-01-31 22:29:41 +0100
commit57c4df1f44a67ddb19e4b02d9c04cb9cf91fd32d (patch)
tree40ffb81b346b8cd9d02de89e141950b2f32af27c
parentada1dc01a41785241404bc486713def52344830e (diff)
Create hanoi.cc
-rw-r--r--hanoi.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/hanoi.cc b/hanoi.cc
new file mode 100644
index 0000000..b401060
--- /dev/null
+++ b/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;
+}