...

View Full Version : Looping through all combinations



DavidB3ck
07-16-2012, 11:54 PM
Hi. I'm new here and such. It's been a few years since I've been on any coding forums, but this one seems to be the most active from the forums I remember.

Anyway, I know this has been discussed many times before, but what I'm trying to do is a little different, and I have yet to find or come up with any satisfactory solutions. Basically, given the array, $arr = array(0, 1, 2, 3, 4);, I want to produce the following results:


01234
0123
0124
0134
0234
1234
012
013
014
023
024
034
123
124
134
234
01
02
03
04
12
13
14
23
24
34
0
1
2
3
4


The order of the elements in the array are from most to least important. In other words, the order of the results are from most to least important, or most to least similar to the original array.
Right now I can't even think of how to get started, so any help would be greatly appreciated.

Thanks!

DrDOS
07-17-2012, 04:26 AM
How similar this is to something I am working with/on! This is a problem in combinatorics, to give it a mathematical name. You have 5 distinct items, they can be ordered in 120 ways, you only want them ordered in 20 particular ways, quite interesting.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum