Skip to content

Instantly share code, notes, and snippets.

@gabrielsaints
Created February 21, 2020 13:17
Show Gist options
  • Save gabrielsaints/538dfe8a45960005dff26e7f386fa94f to your computer and use it in GitHub Desktop.
Save gabrielsaints/538dfe8a45960005dff26e7f386fa94f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
using namespace std;
int hanoi(int n)
{
if(n == 1)
return 1;
else
return 2 * hanoi(n-1) + 1;
}
int main()
{
int disks ;
cout<< "HANOI TOWER\n\n";
cout<< "Number of disks: ";
cin>> disks;
cout<<"\nMovements: ";
cout<< hanoi(disks);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment