Skip to content

Instantly share code, notes, and snippets.

@fabiocicerchia
Forked from gfabrizi/TheUnexpectedFizzBuzz.php
Last active March 10, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiocicerchia/80b6937d316660a05eb6e54579b73d2e to your computer and use it in GitHub Desktop.
Save fabiocicerchia/80b6937d316660a05eb6e54579b73d2e to your computer and use it in GitHub Desktop.
A different (...veeeery different) approach to the good old PHP FizzBuzz test
#!/usr/bin/env php
<?php
if ($argc !== 2 || !ctype_digit($argv[1]))
die('You must specifiy only one parameter: the max number as an integer' . PHP_EOL);
for ($input = (int) $argv[1], $i = 0; $i < $input; ) echo ([
0 => 'FizzBuzz',
3 => 'Fizz', 6 => 'Fizz', 9 => 'Fizz', 12 => 'Fizz',
5 => 'Buzz', 10 => 'Buzz',
][++$i % 15] ?? $i) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment