From 57c4df1f44a67ddb19e4b02d9c04cb9cf91fd32d Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 31 Jan 2017 22:29:41 +0100 Subject: Create hanoi.cc --- hanoi.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 hanoi.cc 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 + +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; +} -- cgit v1.2.3-18-g5258