Page 1 of 1

Who knows how to do this...lol...

Posted: Mon Jan 09, 2006 10:48 am
by jclarkkent2003
Hi,
I ran into another problem just now.

I need to build a small php script that can take a phrase or 2-3 words or more, and find every re arrangement:

example:

user enters:

php - it just outputs php
php dev - it outputs "php dev" and "dev php"
php dev network - it outputs "php dev network" and "dev php network" and " network dev php" and all the other of the 9 possibilities.

I'd like this to go up to like 9 MAXimum.

Who has a script I can look at and modifiy a function?

I'm sure this has to do with like two or more loops but I can't quite code it even though it's so simple.

Posted: Mon Jan 09, 2006 11:17 am
by anjanesh
There was a discussion reagarding this here. Most of the BBCodes aren't proper though - I just edited them.

Posted: Mon Jan 09, 2006 1:37 pm
by jclarkkent2003
thanks, that should do exactly what I was looking for, just gotta slightly modifiy :)

God I love this forum~!

EDIT: Except now I see it's char by char, gotta modifiy a little more than slightly to store each word in an array like this , $array = explode(" ",$string) , then modifiy so it uses the array.

Posted: Mon Jan 09, 2006 1:46 pm
by timvw
shouldn't be too hard to adapt it.. As soon as the applied algorithm becomes clear :)

recursion:
- When there is only one element, simply return that element (only possibility)
- Otherwise: Place each character in front, and then make all possible permutations with the remaining

Posted: Mon Jan 09, 2006 5:27 pm
by spamyboy
:)