Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!jarthur!dfoster From: dfoster@jarthur.Claremont.EDU (Derek R. Foster) Newsgroups: comp.lang.c Subject: Re: number producing algorithm Message-ID: <6226@jarthur.Claremont.EDU> Date: 14 Apr 90 08:20:16 GMT References: <19416@boulder.Colorado.EDU> Distribution: usa Organization: Harvey Mudd College, Claremont, CA 91711 Lines: 75 In article <19416@boulder.Colorado.EDU> baileyc@tramp.Colorado.EDU (BAILEY CHRISTOPHER R) writes: >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 ... This was a fun one to do. I like little challenges like this; they're a like crossword puzzles. I found a reasonably nice solution to it. It seems to work OK, although you might be able to eliminate the recursion with a little massaging. Try this: #include void recurse(int *numlist, int num, int maxnum) { int i,j,norepeats; if (num >= maxnum) { for (j=0; j