//	We have enough to get more, so trade in Chockos and Wrappers for more
     //	If this fails the first time through, Use the $Total_Chockos_On_Hand
     //	as already set up above when we bought the first batch of Chockos
     $Set_While_Loop_Ran = true;
     // Convert New_Chockos on Hand to Wrappers and add to existing Wrappers
     $Wrappers_On_Hand += $New_Chockos;
     EchoBug("While - 1: Wrappers_On_Hand", $Wrappers_On_Hand, 1);
     // Get more Chockos
     $New_Chockos = intval($Wrappers_On_Hand / $M_Wrappers_Reqd);
     EchoBug("While: New_Chockos", $New_Chockos, 1);
     // Keep Remaining Wrappers (MOD $M_Wrappers_Reqd)
     $Wrappers_On_Hand = $Wrappers_On_Hand % $M_Wrappers_Reqd;
     EchoBug("While: Remaining Wrappers_On_Hand", $Wrappers_On_Hand, 1);
     // Keep a running total of all Chockos Bought & Traded
     $Total_Chockos_On_Hand += $New_Chockos;
     EchoBug("While: Total_Chockos_On_Hand", $Total_Chockos_On_Hand, 0);
 }
 //	End While
 //	Write Final Answer
 $FinalAnswer = $Total_Chockos_On_Hand;
 if (ShowOutput == "YES") {
     echo "<strong><em>";
 }
 if (ShowOutput == "YES") {
     echo $Set_While_Loop_Ran ? "While Loop Ran" . aNewLine : "While Loop SKIPPED" . aNewLine;
 }
 EchoAnswer("fwrite Total Chocolates", $FinalAnswer, 1);
 if (ShowOutput == "YES") {
     echo "</strong></em>";
 }
 fwrite($OutPutFileHandle, $FinalAnswer);
Exemplo n.º 2
0
    EchoBug("GET d_Digits", $d_Digits, 1);
    // Strip the Newline \n
    $d_Digits = preg_replace("/[^a-zA-Z0-9]/", "", $d_Digits);
    EchoBug("STRIP d_Digits", $d_Digits, 1);
    // Convert to an array of chars
    $d_DigitsArray = str_split($d_Digits);
    EchoBug("ARRAY d_DigitsArray", $d_DigitsArray, 1);
    // Unique it
    $d_DigitsArray = array_unique($d_DigitsArray);
    EchoBug("ARRAY d_DigitsArray", $d_DigitsArray, 1);
    // Do the Maths
    // For Each item in the array, check to see if it divides evenly (mod == 0) into the original number.
    $ArrayLength = sizeof($d_DigitsArray);
    foreach ($d_DigitsArray as $value) {
        if ($value != 0) {
            EchoBug("{$value}", $value, 1);
            if ($d_Digits % $value == 0) {
                $FinalAnswer += 1;
            }
        }
    }
    // end ForEach
    // Write answer for each line of input
    fwrite($OutPutFileHandle, $FinalAnswer);
    fwrite($OutPutFileHandle, "\n");
    EchoAnswer("FinalAnswer", $FinalAnswer, 0);
}
// End For $TestCases
// Close Files
fclose($InPutFileHandle);
fclose($OutPutFileHandle);
// ## Add to this to Respect the given variable as well as EOF ## //
for ($iii = 1; $iii <= $NumOperations; $iii++) {
    //	Read a Reocrd
    $LineToProcess = fgets($InPutFileHandle);
    $InputArray = explode(" ", $LineToProcess);
    //	Break it down into fields
    $a_IndexStart = $InputArray[0];
    //	Money on Hand
    EchoBug("a_IndexStart", $a_IndexStart, 0);
    $b_IndexEnd = $InputArray[1];
    //	Cost per Chocolate
    EchoBug("b_IndexEnd", $b_IndexEnd, 0);
    // intval the last array item to get rid of the trailing "\n"
    $k_Kandies = intval($InputArray[2]);
    //	Wrappers needed to get another piece of chocolate
    EchoBug("k_Kandies", $k_Kandies, 0);
    // Do the Maths
    $JarsToFill = $b_IndexEnd - $a_IndexStart + 1;
    $KandiesTotal += $JarsToFill * $k_Kandies;
}
// End For $NumOperations
//	Write Final Answer
$FinalAnswer = intval($KandiesTotal / $NumJars);
if (ShowOutput == "YES") {
    echo "<strong><em>";
}
EchoAnswer("fwrite Average Kandies", $FinalAnswer, 1);
if (ShowOutput == "YES") {
    echo "</strong></em>";
}
fwrite($OutPutFileHandle, $FinalAnswer);
        sort($LastArray);
        array_unique($LastArray);
        array_push($StonesArray, end($LastArray));
        EchoBug("Stones Array", $StonesArray, 1);
    }
    //	end for $jjj
}
// End For $TestCases
//	Write Final Answer
// Dummy data for testing sort and unique
//		$StonesArray = $FinalAnswer;
EchoBug("Stones Array", $StonesArray, 1);
$StonesArray = array_unique($StonesArray);
EchoBug("Final Answer", $StonesArray, 1);
sort($StonesArray);
EchoBug("Sorted Answer", $StonesArray, 1);
$FinalAnswer = implode(" ", $StonesArray);
if (ShowOutput == "YES") {
    echo "<strong><em>";
}
EchoAnswer("fwrite ", $FinalAnswer, 1);
if (ShowOutput == "YES") {
    echo "</strong></em>";
}
fwrite($OutPutFileHandle, $FinalAnswer);
fwrite($OutPutFileHandle, "\n");
// Close Files
fclose($InPutFileHandle);
fclose($OutPutFileHandle);
// End Main
?>
// ## Add to this to Respect the given variable as well as EOF ## //
for ($iii = 1; $iii <= $Testcases; $iii++) {
    //	Read a Record/Line, Get 2 Inputs
    $InputLine = fgets($InPutFileHandle);
    $InputLineArray = explode(" ", $InputLine);
    $a_Low = intval($InputLineArray[0]);
    EchoBug("a_Low", $a_Low, 0);
    $b_High = intval($InputLineArray[1]);
    EchoBug("b_High", $b_High, 1);
    // Do the Maths
    $LowInt = ceil(sqrt($a_Low));
    EchoBug("LowInt", $LowInt, 0);
    $HighInt = floor(sqrt($b_High));
    EchoBug("HighInt", $HighInt, 0);
    $DeAnswer = $HighInt - $LowInt + 1;
    EchoBug("DeAnswer", $DeAnswer, 1);
    // Write answer line by line
    $LineAnswer = $DeAnswer;
    if (ShowOutput == "YES") {
        echo "<strong><em>";
    }
    EchoAnswer("fwrite ", $LineAnswer, 1);
    if (ShowOutput == "YES") {
        echo "</strong></em>";
    }
    fwrite($OutPutFileHandle, $LineAnswer);
    fwrite($OutPutFileHandle, "\n");
}
// End For $TestCases
//	Write Final Answer
// $FinalAnswer = $DeAnswer;