Last active
December 27, 2015 00:59
-
-
Save firegate666/7241211 to your computer and use it in GitHub Desktop.
This is a free configurable implementation of the fizzbuzz problem
This file contains 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 | |
$config = array( | |
'fizz' => 3, | |
'buzz' => 5, | |
/* | |
'prim' => function($num) { | |
return in_array($num, array(1, 2, 3, 5, 7, 11, 13, 17, 19, 23)); | |
} | |
*/ | |
); | |
for ($i = 1; $i < 101; $i++) { | |
$output = ''; | |
foreach ($config as $buzzword => $divider) { | |
$is_callable = is_callable($divider); | |
if (($is_callable && $divider($i)) || (!$is_callable && $i % $divider === 0)) { | |
$output .= $buzzword; | |
} | |
} | |
if ($output === '') { | |
$output = $i; | |
} | |
printf('%s ', $output); | |
} | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment