Last active
April 6, 2018 20:36
-
-
Save valeriabarros/47ad0d86cdc80143a821f4117e540daf to your computer and use it in GitHub Desktop.
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 | |
class FizzBuzz { | |
private $pattern; | |
private $result = array(); | |
public function __construct() { | |
$this->pattern = ['', '', 'Fizz', '', 'Buzz', 'Fizz', '', '', 'Fizz', 'Buzz', '', 'Fizz', '', '', 'FizzBuzz']; | |
} | |
private function process() { | |
for ($i = 1; $i <= 100; $i++) { | |
$list = $this->pattern[($i - 1) % 15]; | |
if (!empty($list)) { | |
$this->result[] = $i; | |
continue; | |
} | |
$this->result[] = $list; | |
} | |
return $result; | |
} | |
public function output() | |
{ | |
$data = $this->process(); | |
foreach ($data as $value) { | |
echo $value . PHP_EOL; | |
} | |
} | |
} | |
$class = new Fizzbuzz(); | |
$class->output(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment