Re: Too many arrays! My head is exploding!

From: Date: Tue, 29 May 2012 14:55:11 +0000
Subject: Re: Too many arrays! My head is exploding!
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-318019@lists.php.net to get a copy of this message
On 29 May 2012 18:15, Gary <listgj-phpgeneral@yahoo.co.uk> wrote: > Okay, let's assume I have three "things", A, B, and C. I need to produce > an array with a list of all possible combinations of them, however many > there might be in those combinations: e.g. A, B, C, D, AB, AC, AD, BC, > ABC (not sure if I've missed any!). Normally I'm pretty good at working > this stuff out, but to be honest I'm struggling with this one, at least > to do it in any kind of elegant way. Does anyone have any ideas? Sure, but what you are asking for is a permutation and not a combination. Here's a good read on the subject: http://www.mathsisfun.com/combinatorics/combinations-permutations.html Here's the deciding difference: * If the order doesn't matter, then it's a combination. * If the order does matter, then it's a permutation. A combination of ABC is ABC. However, the permutation of ABC is: ABC ACB BAC BCA CAB CBA Oddly enough, a "combination lock" is a misnomer -- it should be a "permutation lock" because the order of the "combination" does matter. In any event, here's the code for as large a permutation as you may want: http://www.webbytedd.com/b1/permutation/ Cheers, tedd _____________________ tedd.sperling@gmail.com http://sperling.com

« previous php.general (#318019) next »