Combinational Algorithm

Associate
Joined
30 Apr 2003
Posts
1,794
Location
The dark side of the moon
I'm trying to code a combinational algorithm and I'm struggling a little bit.

I am looking to generate every possible, unique 4 digit array from these 10 numbers.
eg.

numbers = [1,2,3,4,5,6,7,8,9,10]
length = 4

Output:
1,2,3,4
1,2,3,5
1,2,3,6
...
...
...
6,7,1,2
6,7,1,3
etc
etc

Can anyone offer any advice?
 
Sorry, I should have been more clear :)

I only want unique numbers.

ie.

4,7,2,3
7,2,9,1

but not

1,1,6,8
4,5,1,4
etc

Hope that makes more sense :)
 
It would be good if they were treated the same in order that the number of combinations is less, but to be honest it doesn't matter that much if 4,9,7,1 is said to be the same as 9,4,7,1.
 
Beansprout said:
Ah cool. I remember all this now :D

I have a handy page here which may help. There's a section on there which'll show all the combinations - I don't want to give you the answer but I haven't found a tutorial as such on the concepts.

And it's written in un-commented obscure Javascript anyway so to interpret it (I believe the relevant function from the source code is doperm() ) you'll need to have a rough idea of the theories anyway, which I guess you do, or you wouldn't be trying/having to do this :)
Thanks, that helped a lot.

I'm going to try coding my own in C# based on that now. I'll post the code if/when I get it working :)
 
Back
Top Bottom