Skip to content

Instantly share code, notes, and snippets.

@Sangrail
Created June 14, 2016 11:52
Show Gist options
  • Save Sangrail/a0cd8574fb84a1eb84b3ecb709d7464e to your computer and use it in GitHub Desktop.
Save Sangrail/a0cd8574fb84a1eb84b3ecb709d7464e to your computer and use it in GitHub Desktop.
Towers of Hanoi
#include <iostream>
#include <map>
using namespace std;
map<int, char> lookup = {{1, 'a'}, {2, 'b'}, {3, 'c'}};;
void hanoi(int numDisks, int source, int destination, int open)
{
if(numDisks>0)
{
hanoi(numDisks-1, source, open, destination);
cout << "Moving " << lookup[numDisks] << " from " << source << " to " << destination << endl;
hanoi(numDisks-1, open, destination, open);
}
}
void main()
{
hanoi(3, 1, 3, 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment