Re: Combination or Permutation question!
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Combination or Permutation question!

From: Alkimake <alkimake@gmail.com>
Date: Wed Mar 29 2006 - 14:28:03 CEST

Here is the answer that Oli found :)

function getCombinations($values)
{
        $perms = array(null);
        foreach ($values as $key => $v)
        {
                $temp = $values;
                                for ($i=0; $i<=$key; $i++) {
                        unset($temp[$i]);
                                }
                $newPerms = getCombinations($temp);
                foreach ($newPerms as $perm)
                {
                        $perms[] = ($v . $perm);
                }
        }
        return $perms;
}

By the way this code is perfect. i have never seen a solution like
this. Thank you very much Oli. And second thank is for making me think.
Actually i didn't want somebody to answer me completely because to
understand the algoritm is more more more important than copy & paste
for me. This is impressive.

Actually i did the combinations when i saw your message but it is about
120 lines :) and very slow.

Take care and see ya.

PS: if i had mistakes i am sorry cuz my english is not so good :)
Received on Mon May 1 02:44:03 2006