Combinations is a common problem but not exactly a trivial one! Took me a bit to figure out where to start.
Instead of making if-statements 9 levels deep (that's never efficient!) I'd keep a list of what I'm still allowed to use instead. No doublethink needed if incorrect values aren't still around to grab. Also, an array of what order to grab things in which you can update as you go, and stop when it goes past the end.
Writing this with C++ strings will be much less efficient than C-strings. By treating a C-string like an array we can do, often with single instructions, what C++ would need entire function calls to do.
It run through all 7,893,600 combinations in 1.3 seconds on my 2.3GHz Athlon64, and I've proven all outputs are unique like so:
..if there were any duplicates, 'sort -u' would have removed them and reduced the count from wc -l.
Last edited by Corona688; 10-25-2010 at 02:58 PM..
Reason: more comments igor!