public function AddToBack() { $TempQuery = array(); for ($i = $this->GroupsAllowed; $i <= $this->lengthOfQuery - 1; $i++) { $TempQuery[] = $this->Query[$i]; } for ($i = 0; $i <= $this->GroupsAllowed - 1; $i++) { $TempQuery[] = $this->Query[$i]; } $this->Query = $TempQuery; } } for ($j = 1; $j <= $TestCases; $j++) { $R = $Tests_R[$j - 1]; $MyRoller = new Roller(); $MyRoller->Query = $Tests_Query[$j]; $MyRoller->k = $Tests_k[$j - 1]; $MyRoller->lengthOfQuery = $Tests_N[$j - 1]; for ($i = 1; $i <= $R; $i++) { $MyRoller->GetNextPeople(); $MyRoller->CalculateMoney(); $MyRoller->AddToBack(); } $OutputString .= "Case #" . $j . ": " . $MyRoller->Money . "\n"; } //echo $OutputString; //exit; $myFile = "output.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $OutputString); fclose($fh);