Created
November 10, 2021 07:30
-
-
Save smunchi/a4f1ef89fe56b9d45b38f785a23ea748 to your computer and use it in GitHub Desktop.
integers to roman conversion
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
| function integersToRomanNumeral($number) | |
| { | |
| $values = [1000, 500, 100, 50, 10, 5, 1]; | |
| $romanNumerals = ['M', 'D', 'C', 'L', 'X', 'V', 'I']; | |
| $result = []; | |
| for($i = 0; $i<count($values); $i++) { | |
| while($number >= $values[$i]) { | |
| $number = $number - $values[$i]; | |
| $result[] = $romanNumerals[$i]; | |
| } | |
| } | |
| return implode("", $result); | |
| } | |
| echo integersToRomanNumeral(50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment