Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyond-code-github/7d90389acc4ca364abd6 to your computer and use it in GitHub Desktop.
Save beyond-code-github/7d90389acc4ca364abd6 to your computer and use it in GitHub Desktop.
Converts numbers to roman numerals up to 3999
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