RE: [PHP] Combo problems.. Multi Array??
| From: | Ford, Mike [LSS] | Date: | Wed, 16 Jun 2004 08:28:16 +0000 |
| Subject: | RE: [PHP] Combo problems.. Multi Array?? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-188377@lists.php.net to get a copy of this message | ||
On 15 June 2004 00:07, Michael Benbow wrote:
> Thanks Mike,
>
> I have read up a lot on permutation but I'm not completely sure that
> this will solve my problem. From what I can gather
> permutation takes a
> sample (i.e. ABC) and tells you how many different ways it
> can arrange
> the letters, with order mattering. What I need to do is take
> a variable
> number of groups (in my example, 3) and then display the combinations
> of ways that my sample (in my example, 2) can be spread across
> the groups.
Ah, yes -- sorry. Something in your original post must have made me think you just wanted the
number of ways, not the actual permutations. (And, in any case, I don't think this *is*
actually a permutation, so I think I was doubly trigger happy!)
[...]
> The example again is as follows..
>
> A [1][2] B C
> A B [1][2] C
> A B C [1][2]
> A [1] B [2] C
> A B [1] C [2]
> A [1] B C [2]
> A [2] B [1] C
> A [2] C C [1]
> A B [2] C [1]
>
> Think of the letters as being static amongst all possible
> combinations, and the numbers as the piece of data which is
> varying. In my actual code both fields are integers but this
> isn't really important here.
I've been fiddling with this for half an hour or so, and I'm pretty convinced the solution
is going to involve a recursive function. However, it might help if you could say exactly what you
want as a result: printed out (in a format similar to the above), inserted into a database (how?),
or some sort of PHP data structure (such as a multi-level array) containing all the possible
results?
Don't guarantee to come up with a final (or even an approximate!) solution, but knowing what
you're trying to work towards would help...!
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211