Skip to content

Instantly share code, notes, and snippets.

@valeriabarros
Last active April 6, 2018 20:36
Show Gist options
  • Save valeriabarros/47ad0d86cdc80143a821f4117e540daf to your computer and use it in GitHub Desktop.
Save valeriabarros/47ad0d86cdc80143a821f4117e540daf to your computer and use it in GitHub Desktop.
<?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