Last active
October 17, 2018 22:02
-
-
Save bcremer/4400dc514dcc1e297fa91e2bd867b639 to your computer and use it in GitHub Desktop.
FizzBuzz without Conditionals in PHP
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 | |
$fizzers = [1, 0, 0, 0]; | |
$buzzers = [2, 0, 0, 0, 0]; | |
$words = ['', 'Fizz', 'Buzz', 'FizzBuzz']; | |
foreach (range(1, 100) as $i) { | |
$words[0] = $i; | |
echo $words[$fizzers[$i % 3] + $buzzers[$i % 5]].PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment