Skip to content

Instantly share code, notes, and snippets.

@azhai
Created July 3, 2014 12:35
Show Gist options
  • Save azhai/d07edb35592ebb7e9235 to your computer and use it in GitHub Desktop.
Save azhai/d07edb35592ebb7e9235 to your computer and use it in GitHub Desktop.
FizzBuzz
<?php
# 运行环境:PHP 5.4+
/* 100以内数字报数,5条规则参照https://www.jinshuju.net/f/EGQL3D */
function count_hundred($a, $b, $c)
{
assert ($a > 0 && $a < 10
&& $b > 0 && $b < 10
&& $c > 0 && $c < 10);
$numbers = range(1, 100);
foreach ($numbers as $i) {
echo (strpos($i, $a) === false ? '' : 'Fizz')
?: (
(($i % $a ? '' : 'Fizz')
. ($i % $b ? '' : 'Buzz')
. ($i % $c ? '' : 'Whizz'))
?: $i
);
echo "\n";
}
}
count_hundred(3, 5, 7);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment