Created
February 19, 2013 13:21
-
-
Save dm/4985813 to your computer and use it in GitHub Desktop.
Roman numerals
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 | |
// Originally found this gem on the PHP docs | |
// http://php.net/manual/en/function.base-convert.php#105414 | |
function roman($N) | |
{ | |
$c = 'IVXLCDM'; | |
for ($a = 5, $b = $s = ''; $N; $b++, $a ^= 7) | |
{ | |
for ( | |
$o = $N % $a, $N = $N / $a ^ 0; | |
$o--; | |
$s = $c[$o > 2 ? $b + $N - ($N &= -2) + $o = 1 : $b] . $s | |
); | |
} | |
return $s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment