Skip to content

Instantly share code, notes, and snippets.

@terremoth
Last active April 21, 2021 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terremoth/e0e813d12c6380275054f587d56b1f44 to your computer and use it in GitHub Desktop.
Save terremoth/e0e813d12c6380275054f587d56b1f44 to your computer and use it in GitHub Desktop.
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