/*** Saeteurn, San ect_sfs@ecst.csuchico.edu Lisence: This code can be redistributed in anyway shape or form. Modified in anyway you choose ***/ #include <iostream> #include <string> using namespace std; void solve(int n, string src, string aux, string dst); int main(int argc, char *argv[]) { int n = 0; if(argc > 2 || argc < 2) { cerr << "Error: Invalid Command Line Arguments" << endl; return 1; } else { int n = atoi(argv[1]);//Gets N (Inputted as a Command Line Argument) solve(n,"Source","Auxiliary","Destination"); return 0; } } /* Description: Prints Directions leading to the Solution of a Tower of Hanoi Puzzle with 3 Pegs. Preconditions: n (Number of Disks), src (The Source String), aux (The Auxiliary String), dst (The Destination String) Postconditions: <NONE> */ void solve(int n, string src, string aux, string dst) { if(n == 0) return; else { solve(n-1,src,dst,aux);//Moves From SRC to AUX using DST as an Auxiliary cout << "Move from " << src << " to " << dst << endl;//Prints the Movement solve(n-1,aux,src,dst);//Moves from Aux to DST using SRC as an Auxiliary } }