Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Challenge from BHUT TI as a "FizzBuzz" similar
<?php
declare(strict_types=1);
/*
* coded by Lucas M. Dutra, github.com/terremoth
*/
abstract class Modulize
{
public static function modulus(int $number, int $divisor, $className) : void
{
if ($number % $divisor === 0) {
echo strtoupper($className);
}
}
}
class Bhut extends Modulize
{
public const DIVISOR = 3;
public static function modulize(int $number) : void
{
self::modulus($number, self::DIVISOR, __CLASS__);
}
}
class Ti extends Modulize
{
public const DIVISOR = 5;
public static function modulize(int $number) : void
{
self::modulus($number, self::DIVISOR, __CLASS__);
}
}
class Counter
{
private $start = 0;
private $end;
public function __construct(int $start=0, int $end)
{
$this->start = $start;
$this->end = $end;
}
public function printNumbersChallenge() : void
{
for ($number = $this->start; $number < $this->end; $number++) {
echo $number.' -> ';
Bhut::modulize($number);
Ti::modulize($number);
echo PHP_EOL;
}
}
}
$challengeStartNumber = 0;
$challengeEndNumber = 100;
$counter = new Counter($challengeStartNumber, $challengeEndNumber);
$counter->printNumbersChallenge();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment