Skip to content

Instantly share code, notes, and snippets.

@gfabrizi
Created March 9, 2020 20:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gfabrizi/e12fb32d8382540f48f50ab0fffd97b5 to your computer and use it in GitHub Desktop.
Save gfabrizi/e12fb32d8382540f48f50ab0fffd97b5 to your computer and use it in GitHub Desktop.
A different (...veeeery different) approach to the good old PHP FizzBuzz test
<?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