• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 n Strings taken r at a time El Forum Guest   07-30-2009, 05:06 AM [eluser]The Spider[/eluser] Hi, I have a set of strings \$set={a,b,c,...,z}. My aim is to develop a function to return all possible unique combinations. The function must have 2 arguments. one for the entire set of string and the 2nd argument is an integer. Eg: If the function name is strComb(\$set, 3) will return: abc abd abe abf.... ... abz .... ... .... zzz. (That means abc,acb,bca, bac, cab, cba are taken as identical quantity and so included only once:abc.) Can anyone help me? El Forum Guest   07-30-2009, 05:17 AM [eluser]jedd[/eluser] [quote author="The Spider" date="1248969994"] Can anyone help me?[/quote] Have you tried asking your teacher and/or the other people in your class that got this homework question? El Forum Guest   07-30-2009, 06:02 AM [eluser]The Spider[/eluser] Hi jedd, Thanks for your response. No one has any idea about this. I didnt get any help. El Forum Guest   08-05-2009, 03:33 AM [eluser]The Spider[/eluser] Hi, I got it!!! function stringPermute(\$string,\$num){ \$last = substr(\$orgString, 0, \$num); \$result = array(); while(\$last != substr(\$orgString, -\$num)){ \$result[] = \$last; \$last = getNextString(\$orgString,\$last,\$num-1); } \$result[] = \$last; return \$result; } function getNextString(\$fullString,\$string,\$char){ if(\$string{\$char} <> lastElement(\$fullString)){ \$string{\$char} = \$fullString{strpos(\$fullString,\$string{\$char})+1}; return \$string; }else{ \$string = change(\$string,\$fullString{0},\$char); return getNextString(\$fullString,\$string,\$char-1); } } function lastElement(\$string){ return \$string{strlen(\$string)-1}; } function change(\$string,\$char,\$start = 0,\$end = 0){ if(\$end == 0) \$end = strlen(\$string)-1; for(\$i=\$start;\$i<=\$end;\$i++){ \$string{\$i} = \$char; } return \$string; } \$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; try stringPermute(\$string,3)