Created
March 9, 2020 20:08
-
-
Save gfabrizi/e12fb32d8382540f48f50ab0fffd97b5 to your computer and use it in GitHub Desktop.
A different (...veeeery different) approach to the good old PHP FizzBuzz test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($argc !== 2 || !ctype_digit($argv[1])) { | |
echo "You must specifiy only one parameter: the max number as an integer" . PHP_EOL; | |
exit(1); | |
} | |
$input = (int) $argv[1]; | |
$fizzBuzz = [ | |
0 => "FizzBuzz", | |
3 => "Fizz", | |
5 => "Buzz", | |
6 => "Fizz", | |
9 => "Fizz", | |
10 => "Buzz", | |
12 => "Fizz", | |
]; | |
for ($i = 1; $i <= $input; $i++) { | |
echo ($fizzBuzz[$i%15] ?? $i) . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment