Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Whole Numbers to Roman Numerals
- Coded by errorseven @ 11-17-2018
- A Numeral surrounded by Parenthesis denotes x 1000
- */
- roman(i) { ; Supports up to 4,999,999,999
- rn:=[["I","V"],["X","L"],["C","D"],["M","(V)"]
- ,["(X)","(L)"],["(C)","(D)"],["(M)","((V))"]
- ,["((X))","((L))"],["((C))","((D))"],["((M))"]]
- While(i) {
- l:=Strlen(i),n:=SubStr(i, 1, 1)
- i:= SubStr(i, 2),r.=(n=9?rn[l].2 rn[l+1].1
- :(n>5&&n<9)?rn[l].2 aV(n,rn[l].1)
- :n=4?rn[l].1 rn[l].2:(n<4&&n>1)?aV(n, rn[l].1)
- :n=5?rn[l].2:n=1?rn[l].1:_)
- } return r
- }
- aV(n,v) {
- n:=n>5?n-5:n
- loop % n
- r.=v
- return r
- }
Add Comment
Please, Sign In to add comment