Last active
April 21, 2021 01:41
-
-
Save terremoth/e0e813d12c6380275054f587d56b1f44 to your computer and use it in GitHub Desktop.
Challenge from BHUT TI as a "FizzBuzz" similar
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 | |
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