Jump to content

How to make this loop?


dimkasmir

Recommended Posts

I don't think a for loop would work because I need the program to go through all possible combinations in multiple variables. For example, I have variables $X $Y and $Z. I know that all of them are less than 9 and $X > $Y $Y > $Z and $X + $Y + $Z = 25. How would I make a loop that tried all the possible combinations of x y and z until they match the conditions?

Link to comment
Share on other sites

There are quite a few conditions:

 

(($A + $B + $C) * ($A + $B + $C) == 100 * $X + 10 * $Y + $Z) &&

(($X + $Y + $Z) * ($X + $Y + $Z) != 100 * $A + 10 * $B + $C) &&

((100 * $A + 10 * $B + $C) - ($A + $B + $C) = ($X + $Y + $Z) * ($X + $Y + $Z)) &&

((100 * $X + 10 * $Y + $Z) >= (100 * $A + 10 * $B + $C)) &&

((100 * $X + 10 * $Y + $Z) <= 2 * (100 * $X + 10 * $Y + $Z))

&& ($A => 0) && ($A =< 9

&& ($B => 0) && ($B =< 9

&& ($C => 0) && ($C =< 9

&& ($X => 0) && ($X =< 9

&& ($Y => 0) && ($Y =< 9

&& ($Z => 0) && ($Z =< 9)

 

I want the program to find all 6 variables so that they match these.

Link to comment
Share on other sites

$test = true;
while($test == true){
$x = str_split(rand(5, 999999));
//create formula here note you note $x will contain an array that has rondom number on given lenght 
if (result form formaula == true){
	$test = false
	$result= yoursesult;
}else{
       $test = true;
     }
}

 

maybe...

 

where are those var coming from?

Link to comment
Share on other sites

while($test == true){
$numbers = array($va1,$var2);
array_rand($numbers);
//create formula here note you note $numbers will contain an array that has rondom number on given lenght 
if (result form formaula == true){
	$test = false
	$result= yoursesult;
}
}

 

maybe ...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.