Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Language: Erlang, Char count: 222</h3> <p>EDIT2: Erlang preprocessor allows some sort of unbalanced macros so this version is 9 chars shorter.</p> <pre><code>-module(n2). -export([y/1]). -define(D(V,S),n(N)when N&gt;=V-&gt;[??S|n(N-V)];). y(N)-&gt;io:format(n(N)). ?D(1000,M)?D(900,CM)?D(500,D)?D(400,CD)?D(100,C)?D(90,XC)?D(50,L)?D(40,XL)?D(10,X)?D(9,IX)?D(5,V)?D(4,IV)?D(1,I)n(0)-&gt;[10]. </code></pre> <p>EDIT: Shorter version inspired by <a href="https://stackoverflow.com/questions/394574/code-golf-new-year-edition-integer-to-roman-numeral#394807">Darius version</a> (231 chars)</p> <pre><code>-module(n). -export([y/1]). y(N)-&gt;io:format([n(N),10]). n(N)when N&gt;9-&gt;[Y||C&lt;-n(N div 10),{K,Y}&lt;-lists:zip("IVXLC","XLCDM"),K==C]++o(N rem 10);n(N)-&gt;o(N). o(N)-&gt;lists:nth(N+1,[[]|string:tokens("I II III IV V VI VII VIII IX"," ")]). </code></pre> <p>It's less readable but save 2 chars (233 chars).</p> <pre><code>-module(n). -export([y/1]). -define(D(V,S),n(N)when N&gt;=V-&gt;[??S|n(N-V)]). y(N)-&gt;io:format(n(N)). ?D(1000,M);?D(900,CM);?D(500,D);?D(400,CD);?D(100,C);?D(90,XC);?D(50,L);?D(40,XL);?D(10,X);?D(9,IX);?D(5,V);?D(4,IV);?D(1,I);n(0)-&gt;[10]. </code></pre> <p>Command line version:</p> <pre><code>-module(n). -export([y/1]). -define(D(V,S),n(N)when N&gt;=V-&gt;[??S|n(N-V)]). y([N])-&gt;io:format(n(list_to_integer(N))),init:stop(). ?D(1000,M);?D(900,CM);?D(500,D);?D(400,CD);?D(100,C);?D(90,XC);?D(50,L);?D(40,XL);?D(10,X);?D(9,IX);?D(5,V);?D(4,IV);?D(1,I);n(0)-&gt;[10]. </code></pre> <p>Invocation:</p> <pre><code>$ erl -noshell -noinput -run n y 2009 MMIX </code></pre> <p>EDIT: I saved 17 chars using literal macro expansion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload