Shortest representation in generalised Roman numerals
Find the shortest representation of an integer in generalised Roman numerals. Since there is more than one way to generalise, only the following definition applies to this challenge.
Definition
The digits used are the same as standard Roman numerals:
Digit | Value |
---|---|
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1000 |
A number is represented as a string of digits. To determine the value of the number:
- Find the first occurrence of the largest digit present. Call this the pivotal digit.
- This pivotal digit will be preceded by a prefix of zero or more digits, and will be followed by a suffix of zero or more digits.
- The value of the number is the value of the pivotal digit, minus the value of the prefix, plus the value of the suffix.
The value of the prefix and the suffix are calculated using these same steps, with the special case of a zero length prefix or suffix having value zero.
Note that unlike standard Roman numerals, this generalisation can represent negative integers and zero.
Input
- An integer from -61 to 61, inclusive.
- To emphasise: the input will not always be positive. It will sometimes be negative or zero.
Output
- A string of Roman numeral digits (letters from
IVXLCDM
). - This must be the shortest string that represents the input.
- If there is more than one shortest representation, you may output any of them, but you must output only one of them.
- Note that
-
is not a valid character for the output. A negative input must result in output composed only of digits fromIVXLCDM
. - Your output is only required to be correct for the specified input range. For this specific challenge, you are free to sacrifice correctness outside the specified input range in order to reduce the size of your code. If all of the test cases pass, your code is valid.
Examples
These examples show Roman numeral digits in fixed width
and decimal digits in bold.
Evaluating a string
The representation VIXIX
is evaluated as follows:
-
X
is the largest digit, so the pivotal digit is the firstX
. - The prefix is
VI
and the suffix isIX
. - The value is
pivot - prefix + suffix
, orX - VI + IX
. - Applying the same approach to
VI
givesV + I
, or 6. - Applying the same approach to
IX
givesX - I
, or 9. - So the value is
X - VI + IX
, or 10 - 6 + 9, or 13.
Processing an input integer
For input 4, there are a variety of ways of representing this number:
-
VIIXI
(five digits) isX - (V + I + I) + I
or 10 - (5 + 1 + 1) + 1. -
IIII
(four digits) isI + I + I + I
or 1 + 1 + 1 + 1. -
VIX
(three digits) isX - (V + I)
or 10 - (5 + 1). -
IV
(two digits) isV - I
or 5 - 1.
The shortest representation is IV
, so this is the valid output.
Multiple valid outputs
For input 3, both of the following are the shortest possible representation, so both are valid outputs:
-
III
isI + I + I
or 1 + 1 + 1. -
IIV
isV - (I + I)
or 5 - (1 + 1).
Zero input
For input 0, any of the following are the shortest possible representation, so all are valid outputs:
-
VVX
isX - (V + V)
or 10 - (5 + 5). -
LLC
isC - (L + L)
or 100 - (50 + 50). -
DDM
isM - (D + D)
or 1000 - (500 + 500).
Negative input
For input -5, any of the following are the shortest possible representation, so all are valid outputs:
-
VVVX
isX - (V + V + V)
or 10 - (5 + 5 + 5). -
LLVC
isC - (L + L + V)
or 100 - (50 + 50 + 5). -
DDVM
isM - (D + D + V)
or 1000 - (500 + 500 + 5).
Test cases
Test cases are in the format integer:["valid","output","strings"]
.
Note that you must only output one valid string, not all of them.
1:["I"]
2:["II"]
3:["III","IIV"]
4:["IV"]
5:["V"]
6:["VI"]
7:["VII"]
8:["IIX"]
9:["IX"]
10:["X"]
11:["XI"]
12:["XII"]
13:["IIXV","IXIV","XIII","XIIV"]
14:["IXV","XIV"]
15:["XV"]
16:["XVI"]
17:["XVII"]
18:["IIXX","IXIX","XIIX"]
19:["IXX","XIX"]
20:["XX"]
21:["XXI"]
22:["XXII"]
23:["IIXXV","IXIXV","IXXIV","XIIXV","XIXIV","XXIII","XXIIV"]
24:["IXXV","XIXV","XXIV"]
25:["XXV"]
26:["XXVI"]
27:["XXVII"]
28:["IIXXX","IXIXX","IXXIX","XIIXX","XIXIX","XXIIX","XXIIL"]
29:["IXXX","XIXX","XXIX","XXIL"]
30:["XXX","XXL"]
31:["IXXL","XIXL","XXXI","XXLI"]
32:["IIXXL","IXIXL","IXXLI","XIIXL","XIXLI","XXXII","XXLII"]
33:["XVIIL"]
34:["XVIL"]
35:["XVL"]
36:["IXVL","XIVL","XVLI"]
37:["IIXVL","IXIVL","IXVLI","XIIIL","XIIVL","XIVLI","XVLII"]
38:["XIIL"]
39:["XIL"]
40:["XL"]
41:["IXL","XLI"]
42:["IIXL","IXLI","XLII"]
43:["VIIL"]
44:["VIL"]
45:["VL"]
46:["IVL","VLI"]
47:["IIIL","IIVL","IVLI","VLII"]
48:["IIL"]
49:["IL"]
50:["L"]
51:["LI"]
52:["LII"]
53:["IILV","ILIV","LIII","LIIV"]
54:["ILV","LIV"]
55:["LV"]
56:["LVI"]
57:["LVII"]
58:["IILX","ILIX","LIIX"]
59:["ILX","LIX"]
60:["LX"]
61:["LXI"]
0:["VVX","LLC","DDM"]
-1:["VVIX","LLIC","DDIM"]
-2:["VVIIX","LLIIC","DDIIM"]
-3:["IIVVVX","IILLVC","IIDDVM","IVIVVX","IVVIVX","IVVVXI","ILILVC","ILLIVC","ILLVCI","IDIDVM","IDDIVM","IDDVMI","VIIVVX","VIVIVX","VIVVXI","VVIIIX","VVIIVX","VVIVXI","VVVXII","LIILVC","LILIVC","LILVCI","LLIIIC","LLIIVC","LLIVCI","LLVCII","DIIDVM","DIDIVM","DIDVMI","DDIIIM","DDIIVM","DDIVMI","DDVMII"]
-4:["IVVVX","ILLVC","IDDVM","VIVVX","VVIVX","VVVXI","LILVC","LLIVC","LLVCI","DIDVM","DDIVM","DDVMI"]
-5:["VVVX","LLVC","DDVM"]
-6:["VVVIX","LLVIC","DDVIM"]
-7:["VVVIIX","LLVIIC","DDVIIM"]
-8:["IILLXC","IIDDXM","ILILXC","ILLIXC","ILLXCI","IDIDXM","IDDIXM","IDDXMI","LIILXC","LILIXC","LILXCI","LLIIXC","LLIXCI","LLXCII","DIIDXM","DIDIXM","DIDXMI","DDIIXM","DDIXMI","DDXMII"]
-9:["ILLXC","IDDXM","LILXC","LLIXC","LLXCI","DIDXM","DDIXM","DDXMI"]
-10:["LLXC","DDXM"]
-11:["LLXIC","DDXIM"]
-12:["LLXIIC","DDXIIM"]
-13:["IILLXVC","IIDDXVM","ILILXVC","ILLIXVC","ILLXIVC","ILLXVCI","IDIDXVM","IDDIXVM","IDDXIVM","IDDXVMI","LIILXVC","LILIXVC","LILXIVC","LILXVCI","LLIIXVC","LLIXIVC","LLIXVCI","LLXIIIC","LLXIIVC","LLXIVCI","LLXVCII","DIIDXVM","DIDIXVM","DIDXIVM","DIDXVMI","DDIIXVM","DDIXIVM","DDIXVMI","DDXIIIM","DDXIIVM","DDXIVMI","DDXVMII"]
-14:["ILLXVC","IDDXVM","LILXVC","LLIXVC","LLXIVC","LLXVCI","DIDXVM","DDIXVM","DDXIVM","DDXVMI"]
-15:["LLXVC","DDXVM"]
-16:["LLXVIC","DDXVIM"]
-17:["LLXVIIC","DDXVIIM"]
-18:["IILLXXC","IIDDXXM","ILILXXC","ILLIXXC","ILLXIXC","ILLXXCI","IDIDXXM","IDDIXXM","IDDXIXM","IDDXXMI","LIILXXC","LILIXXC","LILXIXC","LILXXCI","LLIIXXC","LLIXIXC","LLIXXCI","LLXIIXC","LLXIXCI","LLXXCII","DIIDXXM","DIDIXXM","DIDXIXM","DIDXXMI","DDIIXXM","DDIXIXM","DDIXXMI","DDXIIXM","DDXIXMI","DDXXMII"]
-19:["ILLXXC","IDDXXM","LILXXC","LLIXXC","LLXIXC","LLXXCI","DIDXXM","DDIXXM","DDXIXM","DDXXMI"]
-20:["LLXXC","DDXXM"]
-21:["LLXXIC","DDXXIM"]
-22:["LLXXIIC","DDXXIIM"]
-23:["IILLXXVC","IIDDXXVM","ILILXXVC","ILLIXXVC","ILLXIXVC","ILLXXIVC","ILLXXVCI","IDIDXXVM","IDDIXXVM","IDDXIXVM","IDDXXIVM","IDDXXVMI","LIILXXVC","LILIXXVC","LILXIXVC","LILXXIVC","LILXXVCI","LLIIXXVC","LLIXIXVC","LLIXXIVC","LLIXXVCI","LLXIIXVC","LLXIXIVC","LLXIXVCI","LLXXIIIC","LLXXIIVC","LLXXIVCI","LLXXVCII","DIIDXXVM","DIDIXXVM","DIDXIXVM","DIDXXIVM","DIDXXVMI","DDIIXXVM","DDIXIXVM","DDIXXIVM","DDIXXVMI","DDXIIXVM","DDXIXIVM","DDXIXVMI","DDXXIIIM","DDXXIIVM","DDXXIVMI","DDXXVMII"]
-24:["ILLXXVC","IDDXXVM","LILXXVC","LLIXXVC","LLXIXVC","LLXXIVC","LLXXVCI","DIDXXVM","DDIXXVM","DDXIXVM","DDXXIVM","DDXXVMI"]
-25:["LLXXVC","DDXXVM"]
-26:["LLXXVIC","DDXXVIM"]
-27:["LLXXVIIC","DDXXVIIM"]
-28:["IILXXLLC","IILXLXLC","IILXLLCX","IILLXXXC","IILLXXLC","IILLXLCX","IILLLCXX","IIDXXDLM","IIDXDXLM","IIDXDLMX","IIDDXXXM","IIDDXXLM","IIDDXLMX","IIDDLMXX","ILILXXXC","ILILXXLC","ILILXLCX","ILILLCXX","ILXILXLC","ILXILLCX","ILXXILLC","ILXXLILC","ILXXLLCI","ILXLILCX","ILXLXILC","ILXLXLCI","ILXLLCXI","ILLIXXXC","ILLILCXX","ILLXIXXC","ILLXILCX","ILLXXIXC","ILLXXILC","ILLXXXCI","ILLXXLCI","ILLXLCXI","ILLLCXXI","IDIDXXXM","IDIDXXLM","IDIDXLMX","IDIDLMXX","IDXIDXLM","IDXIDLMX","IDXXIDLM","IDXXDILM","IDXXDLMI","IDXDILMX","IDXDXILM","IDXDXLMI","IDXDLMXI","IDDIXXXM","IDDILMXX","IDDXIXXM","IDDXILMX","IDDXXIXM","IDDXXILM","IDDXXXMI","IDDXXLMI","IDDXLMXI","IDDLMXXI","XIILXLLC","XIILLXLC","XIILLLCX","XIIDXDLM","XIIDDXLM","XIIDDLMX","XILILXLC","XILILLCX","XILXILLC","XILXLILC","XILXLLCI","XILLILCX","XILLXILC","XILLXLCI","XILLLCXI","XIDIDXLM","XIDIDLMX","XIDXIDLM","XIDXDILM","XIDXDLMI","XIDDILMX","XIDDXILM","XIDDXLMI","XIDDLMXI","XXIILLLC","XXIIDDLM","XXILILLC","XXILLILC","XXILLLCI","XXIDIDLM","XXIDDILM","XXIDDLMI","XXLIILLC","XXLILILC","XXLILLCI","XXLLIILC","XXLLILCI","XXLLLCII","XXDIIDLM","XXDIDILM","XXDIDLMI","XXDDIILM","XXDDILMI","XXDDLMII","XLIILXLC","XLIILLCX","XLILILCX","XLILXILC","XLILXLCI","XLILLCXI","XLXIILLC","XLXILILC","XLXILLCI","XLXLIILC","XLXLILCI","XLXLLCII","XLLIILCX","XLLILCXI","XLLXIILC","XLLXILCI","XLLXLCII","XLLLCXII","XDIIDXLM","XDIIDLMX","XDIDILMX","XDIDXILM","XDIDXLMI","XDIDLMXI","XDXIIDLM","XDXIDILM","XDXIDLMI","XDXDIILM","XDXDILMI","XDXDLMII","XDDIILMX","XDDILMXI","XDDXIILM","XDDXILMI","XDDXLMII","XDDLMXII","LIILXXXC","LIILXXLC","LIILXLCX","LIILLCXX","LILIXXXC","LILILCXX","LILXIXXC","LILXILCX","LILXXIXC","LILXXILC","LILXXXCI","LILXXLCI","LILXLCXI","LILLCXXI","LXIILXLC","LXIILLCX","LXILILCX","LXILXILC","LXILXLCI","LXILLCXI","LXXIILLC","LXXILILC","LXXILLCI","LXXLIILC","LXXLILCI","LXXLLCII","LXLIILCX","LXLILCXI","LXLXIILC","LXLXILCI","LXLXLCII","LXLLCXII","LLIIXXXC","LLIILCXX","LLIXIXXC","LLIXXIXC","LLIXXXCI","LLILCXXI","LLXIIXXC","LLXIILCX","LLXIXIXC","LLXIXXCI","LLXILCXI","LLXXIIXC","LLXXIILC","LLXXIXCI","LLXXILCI","LLXXXCII","LLXXLCII","LLXLCXII","LLLCXXII","DIIDXXXM","DIIDXXLM","DIIDXLMX","DIIDLMXX","DIDIXXXM","DIDILMXX","DIDXIXXM","DIDXILMX","DIDXXIXM","DIDXXILM","DIDXXXMI","DIDXXLMI","DIDXLMXI","DIDLMXXI","DXIIDXLM","DXIIDLMX","DXIDILMX","DXIDXILM","DXIDXLMI","DXIDLMXI","DXXIIDLM","DXXIDILM","DXXIDLMI","DXXDIILM","DXXDILMI","DXXDLMII","DXDIILMX","DXDILMXI","DXDXIILM","DXDXILMI","DXDXLMII","DXDLMXII","DDIIXXXM","DDIILMXX","DDIXIXXM","DDIXXIXM","DDIXXXMI","DDILMXXI","DDXIIXXM","DDXIILMX","DDXIXIXM","DDXIXXMI","DDXILMXI","DDXXIIXM","DDXXIILM","DDXXIXMI","DDXXILMI","DDXXXMII","DDXXLMII","DDXLMXII","DDLMXXII"]
-29:["ILXXLLC","ILXLXLC","ILXLLCX","ILLXXXC","ILLXXLC","ILLXLCX","ILLLCXX","IDXXDLM","IDXDXLM","IDXDLMX","IDDXXXM","IDDXXLM","IDDXLMX","IDDLMXX","XILXLLC","XILLXLC","XILLLCX","XIDXDLM","XIDDXLM","XIDDLMX","XXILLLC","XXIDDLM","XXLILLC","XXLLILC","XXLLLCI","XXDIDLM","XXDDILM","XXDDLMI","XLILXLC","XLILLCX","XLXILLC","XLXLILC","XLXLLCI","XLLILCX","XLLXILC","XLLXLCI","XLLLCXI","XDIDXLM","XDIDLMX","XDXIDLM","XDXDILM","XDXDLMI","XDDILMX","XDDXILM","XDDXLMI","XDDLMXI","LILXXXC","LILXXLC","LILXLCX","LILLCXX","LXILXLC","LXILLCX","LXXILLC","LXXLILC","LXXLLCI","LXLILCX","LXLXILC","LXLXLCI","LXLLCXI","LLIXXXC","LLILCXX","LLXIXXC","LLXILCX","LLXXIXC","LLXXILC","LLXXXCI","LLXXLCI","LLXLCXI","LLLCXXI","DIDXXXM","DIDXXLM","DIDXLMX","DIDLMXX","DXIDXLM","DXIDLMX","DXXIDLM","DXXDILM","DXXDLMI","DXDILMX","DXDXILM","DXDXLMI","DXDLMXI","DDIXXXM","DDILMXX","DDXIXXM","DDXILMX","DDXXIXM","DDXXILM","DDXXXMI","DDXXLMI","DDXLMXI","DDLMXXI"]
-30:["XXLLLC","XXDDLM","XLXLLC","XLLXLC","XLLLCX","XDXDLM","XDDXLM","XDDLMX","LXXLLC","LXLXLC","LXLLCX","LLXXXC","LLXXLC","LLXLCX","LLLCXX","DXXDLM","DXDXLM","DXDLMX","DDXXXM","DDXXLM","DDXLMX","DDLMXX"]
-31:["IXXLLLC","IXXDDLM","IXLXLLC","IXLLXLC","IXLLLCX","IXDXDLM","IXDDXLM","IXDDLMX","XIXLLLC","XIXDDLM","XXLLLIC","XXDDLIM","XLIXLLC","XLXLLIC","XLLIXLC","XLLXLIC","XLLLICX","XLLLCIX","XDIXDLM","XDXDLIM","XDDIXLM","XDDXLIM","XDDLIMX","XDDLMIX","LIXXLLC","LIXLXLC","LIXLLCX","LXIXLLC","LXXLLIC","LXLIXLC","LXLXLIC","LXLLICX","LXLLCIX","LLIXXLC","LLIXLCX","LLXIXLC","LLXXXIC","LLXXLIC","LLXLICX","LLXLCIX","LLLICXX","LLLCIXX","LLLCXIX","DIXXDLM","DIXDXLM","DIXDLMX","DXIXDLM","DXXDLIM","DXDIXLM","DXDXLIM","DXDLIMX","DXDLMIX","DDIXXLM","DDIXLMX","DDXIXLM","DDXXXIM","DDXXLIM","DDXLIMX","DDXLMIX","DDLIMXX","DDLMIXX","DDLMXIX"]
-32:["IIXXLLLC","IIXXDDLM","IIXLXLLC","IIXLLXLC","IIXLLLCX","IIXDXDLM","IIXDDXLM","IIXDDLMX","IXIXLLLC","IXIXDDLM","IXXLLLIC","IXXDDLIM","IXLIXLLC","IXLXLLIC","IXLLIXLC","IXLLXLIC","IXLLLICX","IXLLLCIX","IXDIXDLM","IXDXDLIM","IXDDIXLM","IXDDXLIM","IXDDLIMX","IXDDLMIX","XIIXLLLC","XIIXDDLM","XIXLLLIC","XIXDDLIM","XXLLLIIC","XXDDLIIM","XLIIXLLC","XLIXLLIC","XLXLLIIC","XLLIIXLC","XLLIXLIC","XLLXLIIC","XLLLIICX","XLLLICIX","XLLLCIIX","XDIIXDLM","XDIXDLIM","XDXDLIIM","XDDIIXLM","XDDIXLIM","XDDXLIIM","XDDLIIMX","XDDLIMIX","XDDLMIIX","LIIXXLLC","LIIXLXLC","LIIXLLCX","LIXIXLLC","LIXXLLIC","LIXLIXLC","LIXLXLIC","LIXLLICX","LIXLLCIX","LXIIXLLC","LXIXLLIC","LXXLLIIC","LXLIIXLC","LXLIXLIC","LXLXLIIC","LXLLIICX","LXLLICIX","LXLLCIIX","LLIIXXLC","LLIIXLCX","LLIXIXLC","LLIXXLIC","LLIXLICX","LLIXLCIX","LLXIIXLC","LLXIXLIC","LLXXXIIC","LLXXLIIC","LLXLIICX","LLXLICIX","LLXLCIIX","LLLIICXX","LLLICIXX","LLLICXIX","LLLCIIXX","LLLCIXIX","LLLCXIIX","DIIXXDLM","DIIXDXLM","DIIXDLMX","DIXIXDLM","DIXXDLIM","DIXDIXLM","DIXDXLIM","DIXDLIMX","DIXDLMIX","DXIIXDLM","DXIXDLIM","DXXDLIIM","DXDIIXLM","DXDIXLIM","DXDXLIIM","DXDLIIMX","DXDLIMIX","DXDLMIIX","DDIIXXLM","DDIIXLMX","DDIXIXLM","DDIXXLIM","DDIXLIMX","DDIXLMIX","DDXIIXLM","DDXIXLIM","DDXXXIIM","DDXXLIIM","DDXLIIMX","DDXLIMIX","DDXLMIIX","DDLIIMXX","DDLIMIXX","DDLIMXIX","DDLMIIXX","DDLMIXIX","DDLMXIIX"]
-33:["IILVLXLC","IILVLLCX","IILXVLLC","IILXLVLC","IILXLLCV","IILLVLCX","IILLXVLC","IILLXLCV","IILLLCXV","IIDVDXLM","IIDVDLMX","IIDXVDLM","IIDXDVLM","IIDXDLMV","IIDDVLMX","IIDDXVLM","IIDDXLMV","IIDDLMXV","ILILVLCX","ILILXVLC","ILILXLCV","ILILLCXV","ILVILXLC","ILVILLCX","ILVLILCX","ILVLXILC","ILVLXLCI","ILVLLCXI","ILXILVLC","ILXILLCV","ILXVILLC","ILXVLILC","ILXVLLCI","ILXLILCV","ILXLVILC","ILXLVLCI","ILXLLCVI","ILLILCXV","ILLVILCX","ILLVLCXI","ILLXILCV","ILLXVILC","ILLXVLCI","ILLXLCVI","ILLLCXVI","IDIDVLMX","IDIDXVLM","IDIDXLMV","IDIDLMXV","IDVIDXLM","IDVIDLMX","IDVDILMX","IDVDXILM","IDVDXLMI","IDVDLMXI","IDXIDVLM","IDXIDLMV","IDXVIDLM","IDXVDILM","IDXVDLMI","IDXDILMV","IDXDVILM","IDXDVLMI","IDXDLMVI","IDDILMXV","IDDVILMX","IDDVLMXI","IDDXILMV","IDDXVILM","IDDXVLMI","IDDXLMVI","IDDLMXVI","VIILXLLC","VIILLXLC","VIILLLCX","VIIDXDLM","VIIDDXLM","VIIDDLMX","VILILXLC","VILILLCX","VILXILLC","VILXLILC","VILXLLCI","VILLILCX","VILLXILC","VILLXLCI","VILLLCXI","VIDIDXLM","VIDIDLMX","VIDXIDLM","VIDXDILM","VIDXDLMI","VIDDILMX","VIDDXILM","VIDDXLMI","VIDDLMXI","VLIILXLC","VLIILLCX","VLILILCX","VLILXILC","VLILXLCI","VLILLCXI","VLXIILLC","VLXILILC","VLXILLCI","VLXLIILC","VLXLILCI","VLXLLCII","VLLIILCX","VLLILCXI","VLLXIILC","VLLXILCI","VLLXLCII","VLLLCXII","VDIIDXLM","VDIIDLMX","VDIDILMX","VDIDXILM","VDIDXLMI","VDIDLMXI","VDXIIDLM","VDXIDILM","VDXIDLMI","VDXDIILM","VDXDILMI","VDXDLMII","VDDIILMX","VDDILMXI","VDDXIILM","VDDXILMI","VDDXLMII","VDDLMXII","XIILVLLC","XIILLVLC","XIILLLCV","XIIDVDLM","XIIDDVLM","XIIDDLMV","XILILVLC","XILILLCV","XILVILLC","XILVLILC","XILVLLCI","XILLILCV","XILLVILC","XILLVLCI","XILLLCVI","XIDIDVLM","XIDIDLMV","XIDVIDLM","XIDVDILM","XIDVDLMI","XIDDILMV","XIDDVILM","XIDDVLMI","XIDDLMVI","XVIILLLC","XVIIDDLM","XVILILLC","XVILLILC","XVILLLCI","XVIDIDLM","XVIDDILM","XVIDDLMI","XVLIILLC","XVLILILC","XVLILLCI","XVLLIILC","XVLLILCI","XVLLLCII","XVDIIDLM","XVDIDILM","XVDIDLMI","XVDDIILM","XVDDILMI","XVDDLMII","XLIILVLC","XLIILLCV","XLILILCV","XLILVILC","XLILVLCI","XLILLCVI","XLVIILLC","XLVILILC","XLVILLCI","XLVLIILC","XLVLILCI","XLVLLCII","XLLIILCV","XLLILCVI","XLLVIILC","XLLVILCI","XLLVLCII","XLLLCVII","XDIIDVLM","XDIIDLMV","XDIDILMV","XDIDVILM","XDIDVLMI","XDIDLMVI","XDVIIDLM","XDVIDILM","XDVIDLMI","XDVDIILM","XDVDILMI","XDVDLMII","XDDIILMV","XDDILMVI","XDDVIILM","XDDVILMI","XDDVLMII","XDDLMVII","LIILVLCX","LIILXVLC","LIILXLCV","LIILLCXV","LILILCXV","LILVILCX","LILVLCXI","LILXILCV","LILXVILC","LILXVLCI","LILXLCVI","LILLCXVI","LVIILXLC","LVIILLCX","LVILILCX","LVILXILC","LVILXLCI","LVILLCXI","LVLIILCX","LVLILCXI","LVLXIILC","LVLXILCI","LVLXLCII","LVLLCXII","LXIILVLC","LXIILLCV","LXILILCV","LXILVILC","LXILVLCI","LXILLCVI","LXVIILLC","LXVILILC","LXVILLCI","LXVLIILC","LXVLILCI","LXVLLCII","LXLIILCV","LXLILCVI","LXLVIILC","LXLVILCI","LXLVLCII","LXLLCVII","LLIILCXV","LLILCXVI","LLVIILCX","LLVILCXI","LLVLCXII","LLXIILCV","LLXILCVI","LLXVIILC","LLXVILCI","LLXVLCII","LLXLCVII","LLLCXVII","DIIDVLMX","DIIDXVLM","DIIDXLMV","DIIDLMXV","DIDILMXV","DIDVILMX","DIDVLMXI","DIDXILMV","DIDXVILM","DIDXVLMI","DIDXLMVI","DIDLMXVI","DVIIDXLM","DVIIDLMX","DVIDILMX","DVIDXILM","DVIDXLMI","DVIDLMXI","DVDIILMX","DVDILMXI","DVDXIILM","DVDXILMI","DVDXLMII","DVDLMXII","DXIIDVLM","DXIIDLMV","DXIDILMV","DXIDVILM","DXIDVLMI","DXIDLMVI","DXVIIDLM","DXVIDILM","DXVIDLMI","DXVDIILM","DXVDILMI","DXVDLMII","DXDIILMV","DXDILMVI","DXDVIILM","DXDVILMI","DXDVLMII","DXDLMVII","DDIILMXV","DDILMXVI","DDVIILMX","DDVILMXI","DDVLMXII","DDXIILMV","DDXILMVI","DDXVIILM","DDXVILMI","DDXVLMII","DDXLMVII","DDLMXVII"]
-34:["ILVLXLC","ILVLLCX","ILXVLLC","ILXLVLC","ILXLLCV","ILLVLCX","ILLXVLC","ILLXLCV","ILLLCXV","IDVDXLM","IDVDLMX","IDXVDLM","IDXDVLM","IDXDLMV","IDDVLMX","IDDXVLM","IDDXLMV","IDDLMXV","VILXLLC","VILLXLC","VILLLCX","VIDXDLM","VIDDXLM","VIDDLMX","VLILXLC","VLILLCX","VLXILLC","VLXLILC","VLXLLCI","VLLILCX","VLLXILC","VLLXLCI","VLLLCXI","VDIDXLM","VDIDLMX","VDXIDLM","VDXDILM","VDXDLMI","VDDILMX","VDDXILM","VDDXLMI","VDDLMXI","XILVLLC","XILLVLC","XILLLCV","XIDVDLM","XIDDVLM","XIDDLMV","XVILLLC","XVIDDLM","XVLILLC","XVLLILC","XVLLLCI","XVDIDLM","XVDDILM","XVDDLMI","XLILVLC","XLILLCV","XLVILLC","XLVLILC","XLVLLCI","XLLILCV","XLLVILC","XLLVLCI","XLLLCVI","XDIDVLM","XDIDLMV","XDVIDLM","XDVDILM","XDVDLMI","XDDILMV","XDDVILM","XDDVLMI","XDDLMVI","LILVLCX","LILXVLC","LILXLCV","LILLCXV","LVILXLC","LVILLCX","LVLILCX","LVLXILC","LVLXLCI","LVLLCXI","LXILVLC","LXILLCV","LXVILLC","LXVLILC","LXVLLCI","LXLILCV","LXLVILC","LXLVLCI","LXLLCVI","LLILCXV","LLVILCX","LLVLCXI","LLXILCV","LLXVILC","LLXVLCI","LLXLCVI","LLLCXVI","DIDVLMX","DIDXVLM","DIDXLMV","DIDLMXV","DVIDXLM","DVIDLMX","DVDILMX","DVDXILM","DVDXLMI","DVDLMXI","DXIDVLM","DXIDLMV","DXVIDLM","DXVDILM","DXVDLMI","DXDILMV","DXDVILM","DXDVLMI","DXDLMVI","DDILMXV","DDVILMX","DDVLMXI","DDXILMV","DDXVILM","DDXVLMI","DDXLMVI","DDLMXVI"]
-35:["VLXLLC","VLLXLC","VLLLCX","VDXDLM","VDDXLM","VDDLMX","XVLLLC","XVDDLM","XLVLLC","XLLVLC","XLLLCV","XDVDLM","XDDVLM","XDDLMV","LVLXLC","LVLLCX","LXVLLC","LXLVLC","LXLLCV","LLVLCX","LLXVLC","LLXLCV","LLLCXV","DVDXLM","DVDLMX","DXVDLM","DXDVLM","DXDLMV","DDVLMX","DDXVLM","DDXLMV","DDLMXV"]
-36:["IVLXLLC","IVLLXLC","IVLLLCX","IVDXDLM","IVDDXLM","IVDDLMX","IXVLLLC","IXVDDLM","IXLVLLC","IXLLVLC","IXLLLCV","IXDVDLM","IXDDVLM","IXDDLMV","VLIXLLC","VLXLLIC","VLLIXLC","VLLXLIC","VLLLICX","VLLLCIX","VDIXDLM","VDXDLIM","VDDIXLM","VDDXLIM","VDDLIMX","VDDLMIX","XIVLLLC","XIVDDLM","XVLLLIC","XVDDLIM","XLIVLLC","XLVLLIC","XLLIVLC","XLLVLIC","XLLLICV","XLLLCIV","XDIVDLM","XDVDLIM","XDDIVLM","XDDVLIM","XDDLIMV","XDDLMIV","LIVLXLC","LIVLLCX","LIXVLLC","LIXLVLC","LIXLLCV","LVLIXLC","LVLXLIC","LVLLICX","LVLLCIX","LXIVLLC","LXVLLIC","LXLIVLC","LXLVLIC","LXLLICV","LXLLCIV","LLIVLCX","LLIXVLC","LLIXLCV","LLVLICX","LLVLCIX","LLXIVLC","LLXVLIC","LLXLICV","LLXLCIV","LLLICXV","LLLCIXV","LLLCXIV","DIVDXLM","DIVDLMX","DIXVDLM","DIXDVLM","DIXDLMV","DVDIXLM","DVDXLIM","DVDLIMX","DVDLMIX","DXIVDLM","DXVDLIM","DXDIVLM","DXDVLIM","DXDLIMV","DXDLMIV","DDIVLMX","DDIXVLM","DDIXLMV","DDVLIMX","DDVLMIX","DDXIVLM","DDXVLIM","DDXLIMV","DDXLMIV","DDLIMXV","DDLMIXV","DDLMXIV"]
-37:["IIILXLLC","IIILLXLC","IIILLLCX","IIIDXDLM","IIIDDXLM","IIIDDLMX","IIVLXLLC","IIVLLXLC","IIVLLLCX","IIVDXDLM","IIVDDXLM","IIVDDLMX","IIXVLLLC","IIXVDDLM","IIXLVLLC","IIXLLVLC","IIXLLLCV","IIXDVDLM","IIXDDVLM","IIXDDLMV","IILILXLC","IILILLCX","IILXILLC","IILXLILC","IILXLLCI","IILLILCX","IILLXILC","IILLXLCI","IILLLCXI","IIDIDXLM","IIDIDLMX","IIDXIDLM","IIDXDILM","IIDXDLMI","IIDDILMX","IIDDXILM","IIDDXLMI","IIDDLMXI","IVLIXLLC","IVLXLLIC","IVLLIXLC","IVLLXLIC","IVLLLICX","IVLLLCIX","IVDIXDLM","IVDXDLIM","IVDDIXLM","IVDDXLIM","IVDDLIMX","IVDDLMIX","IXIVLLLC","IXIVDDLM","IXVLLLIC","IXVDDLIM","IXLIVLLC","IXLVLLIC","IXLLIVLC","IXLLVLIC","IXLLLICV","IXLLLCIV","IXDIVDLM","IXDVDLIM","IXDDIVLM","IXDDVLIM","IXDDLIMV","IXDDLMIV","ILIILXLC","ILIILLCX","ILILILCX","ILILXILC","ILILXLCI","ILILLCXI","ILXIILLC","ILXILILC","ILXILLCI","ILXLIILC","ILXLILCI","ILXLLCII","ILLIILCX","ILLILCXI","ILLXIILC","ILLXILCI","ILLXLCII","ILLLCXII","IDIIDXLM","IDIIDLMX","IDIDILMX","IDIDXILM","IDIDXLMI","IDIDLMXI","IDXIIDLM","IDXIDILM","IDXIDLMI","IDXDIILM","IDXDILMI","IDXDLMII","IDDIILMX","IDDILMXI","IDDXIILM","IDDXILMI","IDDXLMII","IDDLMXII","VLIIXLLC","VLIXLLIC","VLXLLIIC","VLLIIXLC","VLLIXLIC","VLLXLIIC","VLLLIICX","VLLLICIX","VLLLCIIX","VDIIXDLM","VDIXDLIM","VDXDLIIM","VDDIIXLM","VDDIXLIM","VDDXLIIM","VDDLIIMX","VDDLIMIX","VDDLMIIX","XIIILLLC","XIIIDDLM","XIIVLLLC","XIIVDDLM","XIILILLC","XIILLILC","XIILLLCI","XIIDIDLM","XIIDDILM","XIIDDLMI","XIVLLLIC","XIVDDLIM","XILIILLC","XILILILC","XILILLCI","XILLIILC","XILLILCI","XILLLCII","XIDIIDLM","XIDIDILM","XIDIDLMI","XIDDIILM","XIDDILMI","XIDDLMII","XVLLLIIC","XVDDLIIM","XLIIILLC","XLIIVLLC","XLIILILC","XLIILLCI","XLIVLLIC","XLILIILC","XLILILCI","XLILLCII","XLVLLIIC","XLLIIILC","XLLIIVLC","XLLIILCI","XLLIVLIC","XLLILCII","XLLVLIIC","XLLLIICV","XLLLICIV","XLLLCIII","XLLLCIIV","XDIIIDLM","XDIIVDLM","XDIIDILM","XDIIDLMI","XDIVDLIM","XDIDIILM","XDIDILMI","XDIDLMII","XDVDLIIM","XDDIIILM","XDDIIVLM","XDDIILMI","XDDIVLIM","XDDILMII","XDDVLIIM","XDDLIIMV","XDDLIMIV","XDDLMIII","XDDLMIIV","LIIILXLC","LIIILLCX","LIIVLXLC","LIIVLLCX","LIIXVLLC","LIIXLVLC","LIIXLLCV","LIILILCX","LIILXILC","LIILXLCI","LIILLCXI","LIVLIXLC","LIVLXLIC","LIVLLICX","LIVLLCIX","LIXIVLLC","LIXVLLIC","LIXLIVLC","LIXLVLIC","LIXLLICV","LIXLLCIV","LILIILCX","LILILCXI","LILXIILC","LILXILCI","LILXLCII","LILLCXII","LVLIIXLC","LVLIXLIC","LVLXLIIC","LVLLIICX","LVLLICIX","LVLLCIIX","LXIIILLC","LXIIVLLC","LXIILILC","LXIILLCI","LXIVLLIC","LXILIILC","LXILILCI","LXILLCII","LXVLLIIC","LXLIIILC","LXLIIVLC","LXLIILCI","LXLIVLIC","LXLILCII","LXLVLIIC","LXLLIICV","LXLLICIV","LXLLCIII","LXLLCIIV","LLIIILCX","LLIIVLCX","LLIIXVLC","LLIIXLCV","LLIILCXI","LLIVLICX","LLIVLCIX","LLIXIVLC","LLIXVLIC","LLIXLICV","LLIXLCIV","LLILCXII","LLVLIICX","LLVLICIX","LLVLCIIX","LLXIIILC","LLXIIVLC","LLXIILCI","LLXIVLIC","LLXILCII","LLXVLIIC","LLXLIICV","LLXLICIV","LLXLCIII","LLXLCIIV","LLLIICXV","LLLICIXV","LLLICXIV","LLLCIIXV","LLLCIXIV","LLLCXIII","LLLCXIIV","DIIIDXLM","DIIIDLMX","DIIVDXLM","DIIVDLMX","DIIXVDLM","DIIXDVLM","DIIXDLMV","DIIDILMX","DIIDXILM","DIIDXLMI","DIIDLMXI","DIVDIXLM","DIVDXLIM","DIVDLIMX","DIVDLMIX","DIXIVDLM","DIXVDLIM","DIXDIVLM","DIXDVLIM","DIXDLIMV","DIXDLMIV","DIDIILMX","DIDILMXI","DIDXIILM","DIDXILMI","DIDXLMII","DIDLMXII","DVDIIXLM","DVDIXLIM","DVDXLIIM","DVDLIIMX","DVDLIMIX","DVDLMIIX","DXIIIDLM","DXIIVDLM","DXIIDILM","DXIIDLMI","DXIVDLIM","DXIDIILM","DXIDILMI","DXIDLMII","DXVDLIIM","DXDIIILM","DXDIIVLM","DXDIILMI","DXDIVLIM","DXDILMII","DXDVLIIM","DXDLIIMV","DXDLIMIV","DXDLMIII","DXDLMIIV","DDIIILMX","DDIIVLMX","DDIIXVLM","DDIIXLMV","DDIILMXI","DDIVLIMX","DDIVLMIX","DDIXIVLM","DDIXVLIM","DDIXLIMV","DDIXLMIV","DDILMXII","DDVLIIMX","DDVLIMIX","DDVLMIIX","DDXIIILM","DDXIIVLM","DDXIILMI","DDXIVLIM","DDXILMII","DDXVLIIM","DDXLIIMV","DDXLIMIV","DDXLMIII","DDXLMIIV","DDLIIMXV","DDLIMIXV","DDLIMXIV","DDLMIIXV","DDLMIXIV","DDLMXIII","DDLMXIIV"]
-38:["IILXLLC","IILLXLC","IILLLCX","IIDXDLM","IIDDXLM","IIDDLMX","ILILXLC","ILILLCX","ILXILLC","ILXLILC","ILXLLCI","ILLILCX","ILLXILC","ILLXLCI","ILLLCXI","IDIDXLM","IDIDLMX","IDXIDLM","IDXDILM","IDXDLMI","IDDILMX","IDDXILM","IDDXLMI","IDDLMXI","XIILLLC","XIIDDLM","XILILLC","XILLILC","XILLLCI","XIDIDLM","XIDDILM","XIDDLMI","XLIILLC","XLILILC","XLILLCI","XLLIILC","XLLILCI","XLLLCII","XDIIDLM","XDIDILM","XDIDLMI","XDDIILM","XDDILMI","XDDLMII","LIILXLC","LIILLCX","LILILCX","LILXILC","LILXLCI","LILLCXI","LXIILLC","LXILILC","LXILLCI","LXLIILC","LXLILCI","LXLLCII","LLIILCX","LLILCXI","LLXIILC","LLXILCI","LLXLCII","LLLCXII","DIIDXLM","DIIDLMX","DIDILMX","DIDXILM","DIDXLMI","DIDLMXI","DXIIDLM","DXIDILM","DXIDLMI","DXDIILM","DXDILMI","DXDLMII","DDIILMX","DDILMXI","DDXIILM","DDXILMI","DDXLMII","DDLMXII"]
-39:["ILXLLC","ILLXLC","ILLLCX","IDXDLM","IDDXLM","IDDLMX","XILLLC","XIDDLM","XLILLC","XLLILC","XLLLCI","XDIDLM","XDDILM","XDDLMI","LILXLC","LILLCX","LXILLC","LXLILC","LXLLCI","LLILCX","LLXILC","LLXLCI","LLLCXI","DIDXLM","DIDLMX","DXIDLM","DXDILM","DXDLMI","DDILMX","DDXILM","DDXLMI","DDLMXI"]
-40:["XLLLC","XDDLM","LXLLC","LLXLC","LLLCX","DXDLM","DDXLM","DDLMX"]
-41:["IXLLLC","IXDDLM","XLLLIC","XDDLIM","LIXLLC","LXLLIC","LLIXLC","LLXLIC","LLLICX","LLLCIX","DIXDLM","DXDLIM","DDIXLM","DDXLIM","DDLIMX","DDLMIX"]
-42:["IIXLLLC","IIXDDLM","IXLLLIC","IXDDLIM","XLLLIIC","XDDLIIM","LIIXLLC","LIXLLIC","LXLLIIC","LLIIXLC","LLIXLIC","LLXLIIC","LLLIICX","LLLICIX","LLLCIIX","DIIXDLM","DIXDLIM","DXDLIIM","DDIIXLM","DDIXLIM","DDXLIIM","DDLIIMX","DDLIMIX","DDLMIIX"]
-43:["IILVLLC","IILLVLC","IILLLCV","IIDVDLM","IIDDVLM","IIDDLMV","ILILVLC","ILILLCV","ILVILLC","ILVLILC","ILVLLCI","ILLILCV","ILLVILC","ILLVLCI","ILLLCVI","IDIDVLM","IDIDLMV","IDVIDLM","IDVDILM","IDVDLMI","IDDILMV","IDDVILM","IDDVLMI","IDDLMVI","VIILLLC","VIIDDLM","VILILLC","VILLILC","VILLLCI","VIDIDLM","VIDDILM","VIDDLMI","VLIILLC","VLILILC","VLILLCI","VLLIILC","VLLILCI","VLLLCII","VDIIDLM","VDIDILM","VDIDLMI","VDDIILM","VDDILMI","VDDLMII","LIILVLC","LIILLCV","LILILCV","LILVILC","LILVLCI","LILLCVI","LVIILLC","LVILILC","LVILLCI","LVLIILC","LVLILCI","LVLLCII","LLIILCV","LLILCVI","LLVIILC","LLVILCI","LLVLCII","LLLCVII","DIIDVLM","DIIDLMV","DIDILMV","DIDVILM","DIDVLMI","DIDLMVI","DVIIDLM","DVIDILM","DVIDLMI","DVDIILM","DVDILMI","DVDLMII","DDIILMV","DDILMVI","DDVIILM","DDVILMI","DDVLMII","DDLMVII"]
-44:["ILVLLC","ILLVLC","ILLLCV","IDVDLM","IDDVLM","IDDLMV","VILLLC","VIDDLM","VLILLC","VLLILC","VLLLCI","VDIDLM","VDDILM","VDDLMI","LILVLC","LILLCV","LVILLC","LVLILC","LVLLCI","LLILCV","LLVILC","LLVLCI","LLLCVI","DIDVLM","DIDLMV","DVIDLM","DVDILM","DVDLMI","DDILMV","DDVILM","DDVLMI","DDLMVI"]
-45:["VLLLC","VDDLM","LVLLC","LLVLC","LLLCV","DVDLM","DDVLM","DDLMV"]
-46:["IVLLLC","IVDDLM","VLLLIC","VDDLIM","LIVLLC","LVLLIC","LLIVLC","LLVLIC","LLLICV","LLLCIV","DIVDLM","DVDLIM","DDIVLM","DDVLIM","DDLIMV","DDLMIV"]
-47:["IIILLLC","IIIDDLM","IIVLLLC","IIVDDLM","IILILLC","IILLILC","IILLLCI","IIDIDLM","IIDDILM","IIDDLMI","IVLLLIC","IVDDLIM","ILIILLC","ILILILC","ILILLCI","ILLIILC","ILLILCI","ILLLCII","IDIIDLM","IDIDILM","IDIDLMI","IDDIILM","IDDILMI","IDDLMII","VLLLIIC","VDDLIIM","LIIILLC","LIIVLLC","LIILILC","LIILLCI","LIVLLIC","LILIILC","LILILCI","LILLCII","LVLLIIC","LLIIILC","LLIIVLC","LLIILCI","LLIVLIC","LLILCII","LLVLIIC","LLLIICV","LLLICIV","LLLCIII","LLLCIIV","DIIIDLM","DIIVDLM","DIIDILM","DIIDLMI","DIVDLIM","DIDIILM","DIDILMI","DIDLMII","DVDLIIM","DDIIILM","DDIIVLM","DDIILMI","DDIVLIM","DDILMII","DDVLIIM","DDLIIMV","DDLIMIV","DDLMIII","DDLMIIV"]
-48:["IILLLC","IIDDLM","ILILLC","ILLILC","ILLLCI","IDIDLM","IDDILM","IDDLMI","LIILLC","LILILC","LILLCI","LLIILC","LLILCI","LLLCII","DIIDLM","DIDILM","DIDLMI","DDIILM","DDILMI","DDLMII"]
-49:["ILLLC","IDDLM","LILLC","LLILC","LLLCI","DIDLM","DDILM","DDLMI"]
-50:["LLLC","DDLM"]
-51:["LLLIC","DDLIM"]
-52:["LLLIIC","DDLIIM"]
-53:["IILLLVC","IIDDLVM","ILILLVC","ILLILVC","ILLLIVC","ILLLVCI","IDIDLVM","IDDILVM","IDDLIVM","IDDLVMI","LIILLVC","LILILVC","LILLIVC","LILLVCI","LLIILVC","LLILIVC","LLILVCI","LLLIIIC","LLLIIVC","LLLIVCI","LLLVCII","DIIDLVM","DIDILVM","DIDLIVM","DIDLVMI","DDIILVM","DDILIVM","DDILVMI","DDLIIIM","DDLIIVM","DDLIVMI","DDLVMII"]
-54:["ILLLVC","IDDLVM","LILLVC","LLILVC","LLLIVC","LLLVCI","DIDLVM","DDILVM","DDLIVM","DDLVMI"]
-55:["LLLVC","DDLVM"]
-56:["LLLVIC","DDLVIM"]
-57:["LLLVIIC","DDLVIIM"]
-58:["IILLLXC","IIDDLXM","ILILLXC","ILLILXC","ILLLIXC","ILLLXCI","IDIDLXM","IDDILXM","IDDLIXM","IDDLXMI","LIILLXC","LILILXC","LILLIXC","LILLXCI","LLIILXC","LLILIXC","LLILXCI","LLLIIXC","LLLIXCI","LLLXCII","DIIDLXM","DIDILXM","DIDLIXM","DIDLXMI","DDIILXM","DDILIXM","DDILXMI","DDLIIXM","DDLIXMI","DDLXMII"]
-59:["ILLLXC","IDDLXM","LILLXC","LLILXC","LLLIXC","LLLXCI","DIDLXM","DDILXM","DDLIXM","DDLXMI"]
-60:["LLLXC","DDLXM"]
-61:["LLLXIC","DDLXIM"]
Explanations are optional, but I'm more likely to upvote answers that have one.
1 answer
Jelly, 45 bytes
L‘ḃ5MḢ;‘$œṖƲḅ5aị¥⁸N1¦Sṭ
“¢¦½2d‘Çȷ6¡iḃ5ị“IVXLC
A pair of links that takes an integer as its argument and returns a string with the shortest generalised Roman numeral. The TIO link is limited to finding the first 10,000 (rather than million) Roman numerals because it times out otherwise.
Full explanation to follow, but this is a more efficient approach than the recursive one below because each substring of the Roman numerals is effectively memoised and used to calculate the longer ones. It also saves a couple of bytes which is nice!
Previous version Jelly, 47 bytes
MḢ;‘$œṖƲ߀N1¦SƲḢḊ?
“¢¦½2d‘ṗⱮ8ẎÇ€iị⁸ʋ%35ị“I LXVC
(TIO only checks Roman numerals up to length 6 since otherwise times out)
A full program that takes an integer argument and prints a string. Brute forces the answer by generating all possible Roman numerals with digits IVXLC up to length 8, evaluating them using the described method, and then finding the first which has the correct value.
Explanation
MḢ;‘$œṖƲ߀N1¦SƲḢḊ? # Helper link: takes a Roman numeral (but made of the integer values of each digit) and returns its value
Ʋ Ḋ? # If length >1 then following as a monad:
Ʋ # - Following as a monad:
Ḣ # - Head (get first index)
M # - Indices of maximal values
;‘$ # - Concatenate to index plus 1
œṖ # - Split the original Roman numeral at those two indices
߀ # - Call the helper link for each of the two or three groups generated
N1¦ # - Negate first group
S # - Sum
Ḣ # Else: Head
“¢¦½2d‘ṗⱮ8ẎÇ€iị⁸ʋ%35ị“I LXVC # Main link: takes an integer and returns the shortest numeral that evaluates to it
“¢¦½2d‘ # Integers 1,5,10,50,100
ṗⱮ8 # Cartesian power of these for each of 1 to 8
Ẏ # Join outer lists
ʋ # Following as a dyad using the list of lists of integers as the left argument and the main link’s argument as the right
Ç€ # - Call helper link for each of the list of lists of integers
i # - Index of the original main link argument in these (so find the index of the shortest Roman numeral)
ị⁸ # - Index into the list of lists of integers
%35 # Mod 35
ị“I LXVC # Modular index into "I LXVC" (Jelly will terminate the unterminated string at the end of the program)
💎
Created with the help of Luminespire.
0 comment threads