-4

Hi can I use pow instead of writing it like this?

                    $round1 = $max / 2;
                    $round2 = $round1 + ($max / 2 / 2);
                    $round3 = $round2 + ($max / 2 / 2 / 2);
                    $round4 = $round3 + ($max / 2 / 2 / 2 / 2);
                    $round5 ...
                    $final = $max - 1;
                    $third = $max;

Thanks for help!

Karim Ali
  • 61
  • 2
  • 10

2 Answers2

2

You wouldn't happen to be looking for an easier way to do this, would you:

$round = array($max/2);
for ($i=1;i<$max;$i++)
{
    $round[] = $round[$i -1] + $max/pow(2, $i + 1);
}

Of course, array_sum might be worth a peek, too.

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
-1

try this,

 $rount[0]=0;
 for($i=1;$1<upto n rounds;$i++)
 {
   $rount[i]=$round[i-1]+($max/(2*i));
 }
Magendran V
  • 1,411
  • 3
  • 19
  • 33
  • 3
    this is correct for `i` = 1 or 2 but `($max/2/2/2) != ($max/(2*3))` and will not work following this. – Kami Aug 12 '13 at 12:41