68

Perl 69 bytes s;.;y/XVI60-9/CLXVIX/dfor$a[$_].="32e$&"%72726;gefor 1..100;print"@a" Works by way of magic formula. The expression "32e$&"%72726 transforms each digit in the following manner: 0⇒32, 1⇒320, 2⇒3200, 3⇒32000, 4⇒29096, 5⇒56, 6⇒560, 7⇒5600, 8⇒56000, 9⇒50918 After applying the translation ...


40

C There are only so many Roman numerals, since 4000 and higher have no standard notation, and the preprocessor is a wonderful decompression tool, especially if you have no problems with the fact that the code has undefined behaviour. enum{_ #define a_ #define d_ #define g_ #define j_ #define a(x)c(x)b #define b(x)c(x)a #define c(x)x, #define d(x)f(x)e #...


17

Perl, 49 bytes Includes +1 for -p Run with the 0-based index on STDIN, e.g. ecce.pl <<< 14 ecce.pl: #!/usr/bin/perl -p s,(.)\1*,$&/$1%182 .$1,eg for($_=/$/)x$`;y;19;IV Magic formulas are so magic. Normally I would use ($_=//)x$' to make the loop control one byte shorter, but scoring on this site gives that a handicap of 2 so it ends up 1 ...


17

Verbose, 1362 bytes GET A ROMAN NUMERAL TYPED IN BY THE CURRENT PERSON USING THIS PROGRAM AND PUT IT ONTO THE TOP OF THE PROGRAM STACK PUT THE NUMBER MMMM ONTO THE TOP OF THE PROGRAM STACK MOVE THE FIRST ELEMENT OF THE PROGRAM STACK TO THE SECOND ELEMENT'S PLACE AND THE SECOND ELEMENT OF THE STACK TO THE FIRST ELEMENT'S PLACE DIVIDE THE FIRST ELEMENT OF THE ...


15

HTML + JavaScript + CSS (137) HTML (9) <ol></ol> JavaScript (101) for(i=1;i<=100;i++){document.getElementsByTagName('ol')[0].appendChild(document.createElement('li'))} CSS (27) ol{list-style:upper-roman​} Output ... Demo on JSBin


15

Ruby def Object.const_missing(const) i = const.to_s if i =~ /^[IVXLCDM]+$/ #http://codegolf.stackexchange.com/questions/16254/convert-arbitrary-roman-numeral-input-to-integer-output %w[IV,4 IX,9 XL,40 XC,90 CD,400 CM,900 I,1 V,5 X,10 L,50 C,100 D,500 M,1000].map{|s|k,v=s.split ?,;i.gsub!(k,?++v)} eval(i) else super end end Any (...


15

Mathematica - 166 181 bytes A bit more concise than the other Mathematica answer, thanks in part to a more point-free style. c = Characters; r = Riffle; Graphics[r[{0, 0}~Disk~# & /@ Reverse@Accumulate[ l = {3} ~Join~ r[2 Position[c@"IVXLC", #][[1, 1]] - 1 & /@ c@IntegerString[#, "Roman"], 3]], {White, Black}], ImageSize -> 2 ...


15

Common Lisp - 376 331 304 bytes (use-package(car(ql:quickload'vecto)))(lambda(n o &aux(r 3)l p)(map()(lambda(c)(setf l(position c" I V X L C D M")p(append`((set-line-width,l)(centered-circle-path 0 0,(+(/ l 2)r))(stroke))p)r(+ r l 3)))(format()"~@R"n))(with-canvas(:width(* 2 r):height(* 2 r))(translate r r)(map()'eval p)(save-png o))) Examples (1) (...


12

JavaScript (ES6) Use Proxy to catch roman numerals. Testable in Firefox (latest) on JSFiddle. Not testable in Chrome (with Traceur) since Proxy implementation is broken. // Convert roman numeral to integer. // Borrowed from http://codegolf.stackexchange.com/a/20702/10920 var toDecimal = (s) => { var n = 0; var X = { M: 1e3, CM: 900, D: 500, CD: ...


12

Plain English, 1059 1025 678 641 451 399 bytes Saved 34 bytes by removing an error trap. Then saved 384 bytes by golfing. Then saved 190 bytes by combining the division operation with the append operation ("z") into a new operation ("p"). Then saved 52 bytes by golfing. A s is a string. To p a r remainder a s a x string a n number: If the x is "", exit. ...


10

Python 116 better golfed code of scleaver's answer: r=lambda a,b,c:('',a,2*a,3*a,a+b,b,b+a,b+a+a,b+3*a,a+c);print' '.join(i+j for i in r(*'XLC')for j in r(*'IVX'))+' C'


10

C & C++ (Updated Answer) As observed in a comment, my original solution had two problems: Optional parameters are only available in C99 and later standards of the language family. Trailing comma in enum definition is also specific to C99 and later. Since I wanted my code to be as generic as possible to work on older platforms, I decided to take ...


10

Python 3, 281 278 273 269 bytes My first attempt at codegolf, here we go. Tried to do it without looking at the linked question, so it's probably terrible :) def f(n):d=len(str(n))-1;l=10**d;return 0if n<1else(n<l*4and[73,88,67,77,263,242,252,438,417,427][d]+f(n-l))or(l<=n//9and[161,155,144,340,505,494,690,855,844][d]+f(n-9*l))or(n<l*5and[159,...


10

Mathematica, 113 90 83 bytes Thanks to Martin Ender for suggestions that reduced the length by over 25%! Showing off the high-level commands in Mathematica. Nest[Flatten[Characters@{RomanNumeral@#,#2}&@@@Reverse@@@Tally/@Split@#]&,{"I"},#]& A pure function, taking an argument N and outputting the Nth element of this (0-indexed) sequence, as a ...


9

JavaScript (ES6), 238 c=s=>{X={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1} n=eval('W='+s.replace(/[\w]+/g,n=>(o=0,n.replace(/[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,d=>o+=X[d]), o+';W=W')));o='';for(i in X)while(n>=X[i])o+=i,n-=X[i];return o} Usage: c("XIX + LXXX") > "XCIX" c('XCIX + I / L * D + IV') > "MIV" Annotated ...


9

T-SQL, 1974 - 50 = 1924 bytes I know that golfing in SQL is equivalent to playing 18 holes with nothing but a sand wedge, but I relished the challenge of this one, and I think I managed to do a few interesting things methodologically. This does support the vinculum for both input and output. I adopted the convention of using a trailing tilde to represent ...


9

Mathematica, 67 bytes Fold["("<>#<>")"<>#2&,RomanNumeral[#~IntegerDigits~1000]/."N"->""]& Avoids all trouble with M by converting the input to base 1000 and converting each digit separately with RomanNumeral. Then we fold them up by inserting (...) from the left. Unfortunately, Mathematica represents zeros as N so we need to ...


8

sed 144 Most of you will know this little episode from roman times, when Cesar invented the Cesar crypting (aka rot13) using SED. As a big fanatic of SED, he printed the most common used commands: substitute, print, quit and read (SPQR) on signs which he carried with him to teach his soldiers the use of SED. # 63 = sed-file # 81 = this # 144 summa ...


8

Python, 139 print' '.join(' '.join(i+j for j in ' _I_II_III_IV_V_VI_VII_VIII_IX'.split('_'))for i in ' _X_XX_XXX_XL_L_LX_LXX_LXXX_XC'.split('_'))+' C'


8

Mathematica, 33 chars FromDigits[InputString[],"Roman"]


8

Common Lisp The following is a rather lengthy explanation of how I made a macro that you can use like this: (roman-progn (+ XIV XXVIII)) When a macro is called in Common Lisp, it basically acts like a function, only that the arguments are received before they are evaluated. Actually, since in Common Lisp code is just data, what we receive is a (nested) ...


8

HTML+JQuery, 288 HTML <canvas> JS r=3;w=9;c=$('canvas').get(0).getContext('2d') for(i=prompt(),e=100;e-.1;e/=10){ if((x=Math.floor(i/e)%10)==4)d(w)+d(w+2) else if(x==9)d(w)+d(w+4) else{if(x>4)d(w+2) for(j=x%5;j;j--)d(w)} w-=4} function d(R){c.lineWidth=R c.beginPath() c.arc(150,75,r+=R/2,0,7) c.stroke()...


8

CJam (33 30 bytes) "I"{e`{(4md1$^'I*\'V*@}%e_}ri* Online demo Key to the correctness of the implementation is the following theorem: If the first generation is I, no run length is ever greater than five Lemma: if the first generation is I, no string ever contains VVV. Proof is by contradiction. Suppose that there is a first index n for which the nth ...


8

C# (Visual C# Interactive Compiler), 79 109 bytes This seems like a Regex challenge, I'm sure a shorter solution can be found... s=>System.Text.RegularExpressions.Regex.IsMatch(s,"^M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$") Try it online!


8

Wolfram Language (Mathematica), 35 bytes Check[FromRomanNumeral@#<3999,1<0]& Try it online! 5 bytes saved, thanks to @attinat the limitation [1,3999] unfortunateley costs 7 bytes... here is the code for any roman number Wolfram Language (Mathematica), 28 bytes Check[FromRomanNumeral@#,F]& Try it online! the above code works for any ...


8

CP-1610 assembly (Intellivision),  52 ... 48  47 DECLEs1 = 59 bytes Let's try this on a system that predates Perl by a good 7 years. :-) Takes a pointer to a null-terminated string in R4. Sets the Zero flag if the input is a valid Roman numeral, or clears it otherwise. ROMW 10 ; use 10-bit ROM width ...


7

Lua setmetatable(_G, { __index = function(_, k) if k:match"^[IVXLCDM]*$" then local n = 0 for _, v in ipairs{{IV = 4}, {IX = 9}, {I = 1}, {V = 5}, {XL = 40}, {X = 10}, {XC = 900}, {CD = 400}, {CM = 900}, {C = 100}, {D = 500}, {M = 1000}} do local p, q = next(v) local r k, r =...


7

JavaScript (ES6), 136 bytes f=n=>n<4e3?"M1000CM900D500CD400C100XC90L50XL40X10IX9V5IV4I1".replace(/(\D+)(\d+)/g,(_,r,d)=>r.repeat(n/d,n%=d)):`(${f(n/1e3)})`+f(n%1e3) For numbers under 4000, repeats each Roman "letter" as many times as possible, using the list of Roman "letters" and their decimal values. Otherwise recursively builds up the answer ...


7

Java 8, 70 bytes s->s.matches("M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})") Port of @Innat3's C# answer, so make sure to upvote him! Try it online. Explanation: s-> // Method with String parameter and boolean return-type s.matches("...") // Check if the string matches the regex fully // (which ...


6

C, 177 160 147 chars There are shorter solutions, but none in C, so here's my try. New solution, completely different from my previous one: char*c; f(n){ printf("%.*s",n%5>3?2:n%5+n/5,c+=n%5>3?n%4*4:2-n/5); } main(i){ for(;i<100;putchar(32)) c="XLXXXC",f(i/10), c="IVIIIX",f(i++%10); puts("C"); ...


Only top voted, non community-wiki answers of a minimum length are eligible