Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sports Points r/dailyprogrammer
if ($argc <= 1)
exit("No score was passed\n");
$inputScore = (integer) $argv[1];
$x = 0;
$validScores = array($x);
print "Input score: $inputScore\n";
while ($x <= $inputScore) { // Do until last valid score is higher than input score
$array = $validScores;
foreach ($array as $score) { // For each of the valid scores
isScoreValid($score, 3, $inputScore, $validScores); // Field goal
isScoreValid($score, 6, $inputScore, $validScores); // Touchdown
isScoreValid($score, 7, $inputScore, $validScores); // Touchdown + Conversion
$x = isScoreValid($score, 8, $inputScore, $validScores); // Touchdown + Two-point Conversion
exit("Score is invalid\n"); // If input score not found yet, must be invalid
function isScoreValid($score, $points, $target, &$validScores) {
$x = $score + $points;
if (in_array($x, $validScores)) { // Check if this valid score already exists
/*print "Duplicate score: $x ($score + $points)\n";*/
return $x;
$validScores[] = $x; // If new valid score, add to array
print "Potential score: $x ($score + $points)\n";
if ($x == $target) { // Check if valid score is the input score
exit("Score is valid\n");
return $x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.