Solved

Take 8 words and output all possibile phrazes

Posted on 2004-08-01
4
177 Views
Last Modified: 2008-03-10
hi there

I have a form that i can input 8 words but im not sure on how to output the 8 into all possible phrases for example

say the words are just     I am not sure

i
am
not
sure
not sure
i sure
am not sure
i am not sure

and so on

Any one got any suggestions on how to do this

best regards
0
Comment
Question by:playstat
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
newaira earned 500 total points
ID: 11690902
This code was not written by me, but it almost does what you want it to. I hope that you can do the part that is missing, because this sounds like homework, so you should be doing it yourself.

<?
$yourArr;
$pArr;
$n;

perm(array("I ", "am ", "not ", "sure "));

function PrintPerm() {
global $yourArr,$pArr,$n;

for ($i=1; $i <= $n; $i++)
  echo $yourArr[$pArr[$i]-1];
echo "<br>";

return;
}

function swapThem($i,$j) {
global $pArr;

$temp = $pArr[$i];
$pArr[$i] = $pArr[$j];
$pArr[$j] = $temp;
}

function NextPerm() {
global $pArr,$n;

$k = $n-1;
while ($pArr[$k] > $pArr[$k+1]) $k--;
if ($k == 0) return(0);
else
{
$j = $n;
while ($pArr[$k] > $pArr[$j]) $j--;
swapThem($j,$k);
$r = $n;
$s = $k+1;
while ($r > $s)
{
swapThem($r,$s);
$r--;
$s++;
}
}
PrintPerm();
return(1);
}

function perm($array) {
global $yourArr,$pArr,$n;
//Put your array here
$yourArr=$array;

$n = count($yourArr);

for ($i=0; $i <= $n; $i++) $pArr[$i]=$i; //The permutation array.

//Print the array values
PrintPerm();
while (NextPerm()); //Permute and print
}
?>
0
 
LVL 7

Expert Comment

by:zac_charles
ID: 11692473
thats all good except for 3 undefined variable errors....It shouldn't have..

$yourArr;
$pArr;
$n;

..up the top because it is not a class, therefore they do not need to be predefined and it works perfectly without them.

/ Zac Charles
0
 
LVL 3

Expert Comment

by:newaira
ID: 11693328
Sounds good, but you shouldn't be getting errors anyway (I don't).
0
 
LVL 3

Expert Comment

by:pYrania
ID: 11693661
thats a configuration question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now