Post by
nomuken »
https://forums.nicoclub.com/nomuken-u6987.html
Wed Aug 27, 2003 6:49 pm
yeah, after 8 hours i killed the run. the program was only about 1/3 of the way done. on the machine i was running it on it would take about 24 hours to complete, a 3Ghz P4 may be able to do it quicker.
keep in mind, i used a pretty simple and inefficient algorithm, surely there are much quicker ones.
this was my program (a slightly modified version of the one from C/C++ Users Journal):
#include <iostream>#include <string>#include <fstream>using namespace std;
void permute( string prefix, string s, ofstream& file );
main(){ ofstream myFile; myFile.open("results.txt"); permute( "", "PERPENDICULAR", myFile ); return 0;} void permute( string prefix, string s, ofstream& f ){ if ( s.size() <= 1 ) f << prefix << s << endl; else for ( char *p = s.begin(); p < s.end(); p++ ) { char c = *p; s.erase( p ); permute( prefix + c, s, f ); s.insert( p, c ); }}