number producing algorithm

BAILEY CHRISTOPHER R baileyc at boulder.Colorado.EDU
Sun Apr 8 07:34:37 AEST 1990


Help!  I need an algorithm to generate a series of numbers.  This series is
of variable length.  For example, if I pass a 10 to the function, it needs
to generate numbers that have 10 digits.  The catch is that the numbers it
generates can not have more than one of the same digit, so say, the passed
number is 3, it would generate the following:

0 1 2
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0

So, basically, there are n! number of combinations/permutations (whichever
it is).  Also, I would like it to start with 0 1 2 ...  Right now, my 
function just creates all numbers by counting in the base of the number that
is passed (in this case base 3), then it checks to see if there are more
than one of the same digit in the number, if so it throws it out.  This is
being used to create node mappings for multipath graphs.  My function is not
good because it takes forever when you get up to >6 nodes.  Thanks!
Chris Bailey :: baileyc at tramp.Colorado.EDU
One Agro Mountain Biker - Dialed in for ultra gonzo badness!
"No his mind is not for rent, to any god or government" - RUSH
Member of Team Buck Naked of Buckingham Palace



More information about the Comp.lang.c mailing list