Post History
#13: Post edited
Shortest representation in generalised Roman numerals
- Shortest representation in generalised Roman numerals [FINALIZED]
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
Digit | Value----- | ----:I | 1V | 5X | 10L | 50C | 100D | 500M | 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 particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -62 to 62, 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 from `IVXLCDM`.
- - 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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` is `I + I + I` or **1 + 1 + 1**.
- - `IIV` is `V - (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` is `X - (V + V)` or **10 - (5 + 5)**.
- - `LLC` is `C - (L + L)` or **100 - (50 + 50)**.
- - `DDM` is `M - (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` is `X - (V + V + V)` or **10 - (5 + 5 + 5)**.
- - `LLVC` is `C - (L + L + V)` or **100 - (50 + 50 + 5)**.
- - `DDVM` is `M - (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.*
- ```text
- 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"]
- 62:["LXII"]
- 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"]
- -62:["LLLXIIC","DDLXIIM"]
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- # [Posted](https://codegolf.codidact.com/posts/290000)
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -62 to 62, 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 from `IVXLCDM`.
- - 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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` is `I + I + I` or **1 + 1 + 1**.
- - `IIV` is `V - (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` is `X - (V + V)` or **10 - (5 + 5)**.
- - `LLC` is `C - (L + L)` or **100 - (50 + 50)**.
- - `DDM` is `M - (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` is `X - (V + V + V)` or **10 - (5 + 5 + 5)**.
- - `LLVC` is `C - (L + L + V)` or **100 - (50 + 50 + 5)**.
- - `DDVM` is `M - (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.*
- ```text
- 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"]
- 62:["LXII"]
- 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"]
- -62:["LLLXIIC","DDLXIIM"]
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#12: Post edited
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- An integer from -72 to 72, 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 from `IVXLCDM`.
- 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.- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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` is `I + I + I` or **1 + 1 + 1**.
- - `IIV` is `V - (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` is `X - (V + V)` or **10 - (5 + 5)**.
- - `LLC` is `C - (L + L)` or **100 - (50 + 50)**.
- - `DDM` is `M - (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` is `X - (V + V + V)` or **10 - (5 + 5 + 5)**.
- - `LLVC` is `C - (L + L + V)` or **100 - (50 + 50 + 5)**.
- - `DDVM` is `M - (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.*
- ```text
- 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"]
- 62:["LXII"]
- 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"]
- -62:["LLLXIIC","DDLXIIM"]
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -62 to 62, 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 from `IVXLCDM`.
- - 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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` is `I + I + I` or **1 + 1 + 1**.
- - `IIV` is `V - (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` is `X - (V + V)` or **10 - (5 + 5)**.
- - `LLC` is `C - (L + L)` or **100 - (50 + 50)**.
- - `DDM` is `M - (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` is `X - (V + V + V)` or **10 - (5 + 5 + 5)**.
- - `LLVC` is `C - (L + L + V)` or **100 - (50 + 50 + 5)**.
- - `DDVM` is `M - (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.*
- ```text
- 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"]
- 62:["LXII"]
- 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"]
- -62:["LLLXIIC","DDLXIIM"]
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#11: Post edited
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -72 to 72, 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 from `IVXLCDM`.
- - 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.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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` is `I + I + I` or **1 + 1 + 1**.
- - `IIV` is `V - (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` is `X - (V + V)` or **10 - (5 + 5)**.
- - `LLC` is `C - (L + L)` or **100 - (50 + 50)**.
- - `DDM` is `M - (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` is `X - (V + V + V)` or **10 - (5 + 5 + 5)**.
- - `LLVC` is `C - (L + L + V)` or **100 - (50 + 50 + 5)**.
- - `DDVM` is `M - (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.*
- ```text
- 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"]
- 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"]
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -72 to 72, 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 from `IVXLCDM`.
- - 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.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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` is `I + I + I` or **1 + 1 + 1**.
- - `IIV` is `V - (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` is `X - (V + V)` or **10 - (5 + 5)**.
- - `LLC` is `C - (L + L)` or **100 - (50 + 50)**.
- - `DDM` is `M - (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` is `X - (V + V + V)` or **10 - (5 + 5 + 5)**.
- - `LLVC` is `C - (L + L + V)` or **100 - (50 + 50 + 5)**.
- - `DDVM` is `M - (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.*
- ```text
- 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"]
- 62:["LXII"]
- 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"]
- -62:["LLLXIIC","DDLXIIM"]
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#10: Post edited
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- An integer from -127 to 127, inclusive.- Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`- `IIV`- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- `VVX`- `LLC`- `DDM`- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- `VVVX`- `LLVC`- `DDVM`- ## 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.*
- ```text
TODO: test cases- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -72 to 72, 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 from `IVXLCDM`.
- - 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.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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` is `I + I + I` or **1 + 1 + 1**.
- - `IIV` is `V - (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` is `X - (V + V)` or **10 - (5 + 5)**.
- - `LLC` is `C - (L + L)` or **100 - (50 + 50)**.
- - `DDM` is `M - (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` is `X - (V + V + V)` or **10 - (5 + 5 + 5)**.
- - `LLVC` is `C - (L + L + V)` or **100 - (50 + 50 + 5)**.
- - `DDVM` is `M - (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.*
- ```text
- 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"]
- 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"]
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#9: Post edited
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way, with the special case of a zero length prefix or suffix having value zero.- Note that unlike standard Roman numerals, this particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -127 to 127, inclusive.
- - Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`
- - `IIV`
- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVX`
- - `LLC`
- - `DDM`
- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVVX`
- - `LLVC`
- - `DDVM`
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -127 to 127, inclusive.
- - Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`
- - `IIV`
- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVX`
- - `LLC`
- - `DDM`
- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVVX`
- - `LLVC`
- - `DDVM`
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#8: Post edited
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way, with the special case of a zero length prefix or suffix having value zero.
- Note that unlike standard Roman numerals, this particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -127 to 127, inclusive.
- - Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`
- - `IIV`
- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVX`
- - `LLC`
- - `DDM`
- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVVX`
- - `LLVC`
- - `DDVM`
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way, with the special case of a zero length prefix or suffix having value zero.
- Note that unlike standard Roman numerals, this particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -127 to 127, inclusive.
- - Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`
- - `IIV`
- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVX`
- - `LLC`
- - `DDM`
- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVVX`
- - `LLVC`
- - `DDVM`
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#7: Post edited
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way, with the special case of a zero length prefix or suffix having value zero.
- Note that unlike standard Roman numerals, this particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -127 to 127, inclusive.
- - Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`
- - `IIV`
- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVX`
- - `LLC`
- - `DDM`
- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- `DDVM`- `LLVC`- - `VVVX`
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way, with the special case of a zero length prefix or suffix having value zero.
- Note that unlike standard Roman numerals, this particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -127 to 127, inclusive.
- - Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`
- - `IIV`
- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVX`
- - `LLC`
- - `DDM`
- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVVX`
- - `LLVC`
- - `DDVM`
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#6: Post edited
Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way.- ## Input
- A positive integer- The input will never be 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- ## 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 first `X`- The prefix is `VI` and the suffix is `IX`- The value is `pivot - prefix + suffix`, or `X - VI + IX`- Applying the same approach to `VI` gives `V + I`, or **6**- Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**- `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**- `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**- `IV` (two digits) is `V - I` or **5 - 1**- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
For input **3**, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given an integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way, with the special case of a zero length prefix or suffix having value zero.
- Note that unlike standard Roman numerals, this particular generalisation can represent negative integers and zero.
- ## Input
- - An integer from -127 to 127, inclusive.
- - Note that 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 from `IVXLCDM`.
- ## 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 first `X`.
- - The prefix is `VI` and the suffix is `IX`.
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`.
- - Applying the same approach to `VI` gives `V + I`, or **6**.
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**.
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**.
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**.
- - `IV` (two digits) is `V - 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`
- - `IIV`
- ### Zero input
- For input **0**, any of the following are the shortest possible representation, so all are valid outputs:
- - `VVX`
- - `LLC`
- - `DDM`
- ### Negative input
- For input **-5**, any of the following are the shortest possible representation, so all are valid outputs:
- - `DDVM`
- - `LLVC`
- - `VVVX`
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#5: Post edited
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
```textI: 1V: 5X: 10L: 50C: 100D: 500M: 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## 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 first `X`
- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- - Applying the same approach to `VI` gives `V + I`, or **6**
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**
- - `IV` (two digits) is `V - I` or **5 - 1**
- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
- For input **3**, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## 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 first `X`
- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- - Applying the same approach to `VI` gives `V + I`, or **6**
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**
- - `IV` (two digits) is `V - I` or **5 - 1**
- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
- For input **3**, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#4: Post edited
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- ```text
- 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## Examples
- ### Evaluating a string
- The representation `VIXIX` is evaluated as follows:
- - `X` is the largest digit, so the pivotal digit is the first `X`
- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- Applying the same approach to `VI` gives `V + I`, or 6- Applying the same approach to `IX` gives `X - 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` (5 digits) is `X - (V + I + I) + I` or `10 - (5 + 1 + 1) + 1`- `IIII` (4 digits) is `I + I + I + I` or `1 + 1 + 1 + 1`- `VIX` (3 digits) is `X - (V + I)` or `10 - (5 + 1)`- `IV` (2 digits) is `V - I` or `5 - 1`- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
For input `3`, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- ```text
- 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## 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 first `X`
- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- - Applying the same approach to `VI` gives `V + I`, or **6**
- - Applying the same approach to `IX` gives `X - 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) is `X - (V + I + I) + I` or **10 - (5 + 1 + 1) + 1**
- - `IIII` (four digits) is `I + I + I + I` or **1 + 1 + 1 + 1**
- - `VIX` (three digits) is `X - (V + I)` or **10 - (5 + 1)**
- - `IV` (two digits) is `V - I` or **5 - 1**
- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
- For input **3**, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#3: Post edited
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- ```text
- 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## Examples
- ### Evaluating a string
- The representation `VIXIX` is evaluated as follows:
- `X` is the largest digit, so the pivotal digit is the first X- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- - Applying the same approach to `VI` gives `V + I`, or 6
- - Applying the same approach to `IX` gives `X - 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` (5 digits) is `X - (V + I + I) + I` or `10 - (5 + 1 + 1) + 1`
- - `IIII` (4 digits) is `I + I + I + I` or `1 + 1 + 1 + 1`
- - `VIX` (3 digits) is `X - (V + I)` or `10 - (5 + 1)`
- - `IV` (2 digits) is `V - I` or `5 - 1`
- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
- For input `3`, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- ```text
- 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## Examples
- ### Evaluating a string
- The representation `VIXIX` is evaluated as follows:
- - `X` is the largest digit, so the pivotal digit is the first `X`
- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- - Applying the same approach to `VI` gives `V + I`, or 6
- - Applying the same approach to `IX` gives `X - 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` (5 digits) is `X - (V + I + I) + I` or `10 - (5 + 1 + 1) + 1`
- - `IIII` (4 digits) is `I + I + I + I` or `1 + 1 + 1 + 1`
- - `VIX` (3 digits) is `X - (V + I)` or `10 - (5 + 1)`
- - `IV` (2 digits) is `V - I` or `5 - 1`
- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
- For input `3`, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#2: Post edited
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- ```text
- 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## Examples
- ### Evaluating a string
- The representation `VIXIX` is evaluated as follows:
- - `X` is the largest digit, so the pivotal digit is the first X
- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- - Applying the same approach to `VI` gives `V + I`, or 6
- - Applying the same approach to `IX` gives `X - 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` (5 digits) is `X - (V + I + I) + I` or `10 - (5 + 1 + 1) + 1`
- - `IIII` (4 digits) is `I + I + I + I` or `1 + 1 + 1 + 1`
- - `VIX` (3 digits) is `X - (V + I)` or `10 - (5 + 1)`
- - `IV` (2 digits) is `V - I` or `5 - 1`
- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
- For input `3`, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.
- ## Test cases
- Test cases are in the format `integer : ["valid", "output", "strings"]`.
*Note that you must only output one valid string, not all of the them.*- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge.
- ## Definition
- The digits used are the same as for standard Roman numerals, with the same values:
- ```text
- 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 in the same way.
- ## Input
- - A positive integer
- - The input will never be 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
- ## Examples
- ### Evaluating a string
- The representation `VIXIX` is evaluated as follows:
- - `X` is the largest digit, so the pivotal digit is the first X
- - The prefix is `VI` and the suffix is `IX`
- - The value is `pivot - prefix + suffix`, or `X - VI + IX`
- - Applying the same approach to `VI` gives `V + I`, or 6
- - Applying the same approach to `IX` gives `X - 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` (5 digits) is `X - (V + I + I) + I` or `10 - (5 + 1 + 1) + 1`
- - `IIII` (4 digits) is `I + I + I + I` or `1 + 1 + 1 + 1`
- - `VIX` (3 digits) is `X - (V + I)` or `10 - (5 + 1)`
- - `IV` (2 digits) is `V - I` or `5 - 1`
- The shortest representation is `IV`, so this is the valid output.
- ### Multiple valid outputs
- For input `3`, both `III` and `IIV` are the shortest possible representation, so both are valid outputs.
- ## 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.*
- ```text
- TODO: test cases
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#1: Initial revision
Shortest representation in generalised Roman numerals
Given a positive integer, find its shortest representation in generalised Roman numerals. Since there is more than one way to generalise, only the definition shown below applies to this challenge. ## Definition The digits used are the same as for standard Roman numerals, with the same values: ```text 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 in the same way. ## Input - A positive integer - The input will never be 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 ## Examples ### Evaluating a string The representation `VIXIX` is evaluated as follows: - `X` is the largest digit, so the pivotal digit is the first X - The prefix is `VI` and the suffix is `IX` - The value is `pivot - prefix + suffix`, or `X - VI + IX` - Applying the same approach to `VI` gives `V + I`, or 6 - Applying the same approach to `IX` gives `X - 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` (5 digits) is `X - (V + I + I) + I` or `10 - (5 + 1 + 1) + 1` - `IIII` (4 digits) is `I + I + I + I` or `1 + 1 + 1 + 1` - `VIX` (3 digits) is `X - (V + I)` or `10 - (5 + 1)` - `IV` (2 digits) is `V - I` or `5 - 1` The shortest representation is `IV`, so this is the valid output. ### Multiple valid outputs For input `3`, both `III` and `IIV` are the shortest possible representation, so both are valid outputs. ## Test cases Test cases are in the format `integer : ["valid", "output", "strings"]`. *Note that you must only output one valid string, not all of the them.* ```text TODO: test cases ``` > Explanations are optional, but I'm more likely to upvote answers that have one.