Created
July 3, 2014 12:35
-
-
Save azhai/d07edb35592ebb7e9235 to your computer and use it in GitHub Desktop.
FizzBuzz
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 | |
| # 运行环境: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