Created
July 12, 2021 14:23
-
-
Save guillaumebdx/b739cfbbc42dae4709cb5c6d25dccf25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| namespace Roman; | |
| class Roman | |
| { | |
| public const ROMANS = [ | |
| 'M'=>1000, | |
| 'CM'=>900, | |
| 'D'=>500, | |
| 'CD'=>400, | |
| 'C'=>100, | |
| 'XC'=>90, | |
| 'L'=>50, | |
| 'XL'=>40, | |
| 'X'=>10, | |
| 'IX'=>9, | |
| 'V'=>5, | |
| 'IV'=>4, | |
| 'I'=>1, | |
| ]; | |
| public function convert($number) | |
| { | |
| $result = ''; | |
| foreach (self::ROMANS as $key => $value) { | |
| if ($number % $value === 0) { | |
| $result .= str_repeat($key, $number / $value); | |
| $number = 0; | |
| } | |
| } | |
| return $result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment