Last active
August 29, 2015 14:08
-
-
Save beyond-code-github/7d90389acc4ca364abd6 to your computer and use it in GitHub Desktop.
Converts numbers to roman numerals up to 3999
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
public static string From(int n){ | |
var m="I,X,C,M,V,L,D".Split(',');var i=0; | |
Func<int,string>x=y=>new string(m[i++][0],y-48); | |
return(n+"").Reverse().Aggregate("",(r,c)=>(c<52?x(c):c==52?m[i]+m[4+i++]:c<57?m[i+4]+x(c-5):m[i]+m[1+i++])+r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment