function GeneralCase($N) { global $DecentNumber, $Max5s, $Max3s, $SolutionFound; // If (($N % 3) == 0 ) // Nailed it! (This will succeed 1 out of 3 times) // return / break; // else $xxx = round($N / 3 + 1); // Limit of 3 chunked "555"s for (; $xxx >= 0; $xxx--) { // Loop y $yyyyy = round($N / 5 + 1); // Limit of 5 chunked "33333"s for (; $yyyyy >= 0; $yyyyy--) { echo "xxx = " . $xxx . ", yyyyy = " . $yyyyy . "\n"; // For testing if ($xxx * 3 + $yyyyy * 5 == $N) { $SolutionFound = TRUE; $Max5s = $xxx; $Max3s = $yyyyy; $DecentNumber = AssembleString($Max5s, $Max3s); return; } // End If } // End $yyyyy Loop } // End $xxx Loop // both x and y loops searched, no answer found $DecentNumber = "Fail -1 (General Case Loop Completion \n\n"; // return fail; }
function GeneralCase($N) { global $DecentNumber, $Max5s, $Max3s, $SolutionFound; // Special Case: If MOD 3 = 0; THEN we Nailed it! (This will succeed 1 out of 3 times) if ($N % 3 == 0) { $SolutionFound = TRUE; $Max5s = $N / 3; $Max3s = 0; $DecentNumber = AssembleString($Max5s, $Max3s); return; } else { // General Case - We loop thru the possibilities of ($xxx * 3) + ($yyyyy * 5) = $N // $xxx is the 3 digit number "555" and $yyyyy is the 5 digit number "33333" // Outer Loop $xxx $xxx = round($N / 3 + 1); // Limit of 3 chunked "555"s for (; $xxx >= 0; $xxx--) { // Inner Loop $yyyyy $yyyyy = round($N / 5 + 1); // Limit of 5 chunked "33333"s for (; $yyyyy >= 0; $yyyyy--) { // echo "xxx = " . $xxx . ", yyyyy = " . $yyyyy . "\n"; // For testing if ($xxx * 3 + $yyyyy * 5 == $N) { $SolutionFound = TRUE; $Max5s = $xxx; $Max3s = $yyyyy; $DecentNumber = AssembleString($Max5s, $Max3s); return; } // End If } // End $yyyyy Loop } // End $xxx Loop // both x and y loops searched, no answer found echo "-1 Fail <br> \n"; $SolutionFound = FALSE; //No Longer Used // return fail; } // End Else }
function GeneralCase($N) { // Special Case: If MOD 3 = 0; THEN we Nailed it! (This will succeed 1 out of 3 times) if ($N % 3 == 0) { $Max5s = $N / 3; $Max3s = 0; $DecentNumber = AssembleString($Max5s, $Max3s); return $DecentNumber; } else { // General Case - We loop thru the possibilities of ($xxx * 3) + ($yyyyy * 5) = $N // $xxx is the 3 digit number "555" and $yyyyy is the 5 digit number "33333" // Outer Loop $xxx $xxx = round($N / 3 + 1); // Limit of 3 chunked "555"s for (; $xxx >= 0; $xxx--) { // Inner Loop $yyyyy $yyyyy = round($N / 5 + 1); // Limit of 5 chunked "33333"s for (; $yyyyy >= 0; $yyyyy--) { if ($xxx * 3 + $yyyyy * 5 == $N) { $Max5s = $xxx; $Max3s = $yyyyy; $DecentNumber = AssembleString($Max5s, $Max3s); return $DecentNumber; } // End If } // End $yyyyy Loop } // End $xxx Loop // both x and y loops searched, no answer found - return FAIL as a -1 $DecentNumber = '-1'; return $DecentNumber; } // End Else }