Jump to content

Loop problem


cwarn23

Recommended Posts

Hi, I am trying to reverse a loop but am having some troubles. Below is an example of my problem but I need to find the value of $c in each round of the second loop. Does anybody know how to find the value of $c in the second loop because I'm stuck in the middle of thick woods.

<?php
$a=1;
$b=47;
$c=88;
$tmp=23;
for($i=0;$i<80;$i++) {
$random_number=floor(mt_rand(0,1000));
echo $random_number.'<br>';
$tmp=($tmp+$c+$random_number)*0.5;
$c=$b;
$b=$a;
$a=$tmp;
}


//Now to reverse
echo '<hr>';


$tmp=$a;
for ($i=0;$i<80;$i--) {
$a=$b;
$b=$c;
//$c=(unknown);
//$random_number=(($tmp-$c)-$a)*2;
//$tmp=($tmp-(($random_number*0.5)+$c+$a))*2;
//echo $random_number.'<br>';
}
?>

Also the objective in this script is to find $random_number for each loop round by appending new code instead of altering the original.

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/193425-loop-problem/
Share on other sites

Just an update, I saw that code has an infinit loop so it is as follows.

<?php
$a=1;
$b=47;
$c=88;
$tmp=23;
for($i=0;$i<80;$i++) {
$random_number=floor(mt_rand(0,1000));
echo $random_number.'<br>';
$tmp=($tmp+$c+$random_number)*0.5;
$c=$b;
$b=$a;
$a=$tmp;
}


//Now to reverse
echo '<hr>';


$tmp=$a;
for ($i=0;$i<80;$i++) {
$a=$b;
$b=$c;
//$c=(unknown);
//$random_number=(($tmp-$c)-$a)*2;
//$tmp=($tmp-(($random_number*0.5)+$c+$a))*2;
//echo $random_number.'<br>';
}
?>

And why isn't anyone replying.

Link to comment
https://forums.phpfreaks.com/topic/193425-loop-problem/#findComment-1018759
Share on other sites

I have not replied cause what you are doing is greek to me.

You loop through 80 times displaying a random number while doing a bunch of other greeky stuff that does nothing to the results of the random number and that you never use elsewhere. Whats to answer?

 

 

HTH

Teamtomic

Link to comment
https://forums.phpfreaks.com/topic/193425-loop-problem/#findComment-1018830
Share on other sites

Whats to answer?

Basically I need to find the value of $c and $c is the same as what $tmp will be in two loops time. So I need to predict what $tmp will be in two loops time and assign it to $c. Does anyone know how to do that as it would solve not only this problem but part of a bigger problem I am dealing with. Surly something as simple as this can be solved.

Link to comment
https://forums.phpfreaks.com/topic/193425-loop-problem/#findComment-1018833
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.