Re: algorithm help ?
| From: | Unknown Sender | Date: | Sat, 30 Dec 2000 01:01:44 +0000 |
| Subject: | Re: algorithm help ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32271@lists.php.net to get a copy of this message | ||
On Fri, Dec 29, 2000 at 11:47:08AM +0200, Gianni Ponzi wrote:
> ok
>
> this is what i'd like to do....
>
> I'd like to be able to select 19 numbers between 1 and 49 and work out
> the permutations / combinations of those numbers in groups of six.
First of all, you can pick 19 numbers, and store them as say
a[1], ..., a[19].
> eg 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
Then you can do it with these numbers, but give output using the a array.
> results:
>
> 1 2 3 4 5 6
> 1 2 3 5 6 7
> 1 2 3 6 7 8
>
>
> and so on.....
Think you should first find all subsets of { 1, 2, ..., 19 } with 6
elements. If you put those into an array b[1], ..., b[6], you can
compute the permutations of 1, ..., 6 once.
So, actually, I would first find all permutations of 1, ..., 6. Then
find all the interesting subsets of 1, ..., 19, and finally pick the
19 numbers to use. If the permutations are in a two-dimensional array
p, you could then print the result looping through p and printing
a[b[p[i][j]]].
Finding all permutations is pretty easy, finding all subsets of
1, ..., 19 with 6 elements shouldn't be that hard either. This
might work:
The highest value in our subset can be anything from 6 up to 19.
So we loop through those. Let h be the current value. Then you
need to pick all subsets of 1, ..., h-1 with 5 elements. Just
repeat this process.
Stig