15
2
Roman numerals can be (mostly) written in a one column format, because each letter intersects the top and the bottom of the line. For example: I
, or 1 intersects both the top and bottom of the line, and V
or 5 intersects the bottom and top lines, the top twice and the bottom at one place.
The value of all roman numerals is as follows:
I = 1
V = 5
X = 10
L = 50
C = 100
D = 500
M = 1000
and the number of intersections (top, bottom) is:
I = 1,1
V = 2,1
X = 2,2
L = 1,2
C = 1,1
D = 1,1
M = 2,3
Your job is to take in 2 numbers, which represent the number of intersections on the top and bottom of your line (in that order), and output all possible valid combinations of roman numerals, from smallest by literal value to largest. Inputs will always be at or above 1.
Here are some test cases:
Input: 1,1
Output: I,C,D
Input: 1,2
Output: L
Input: 2,1
Output: V
Input: 2,2
Output: II, X, IC, CI, CC, ID, DI
(note that DD is not a valid roman numeral, and thus should not be outputted, the value of all of these is (in order) 2, 10, 99, 101, 499, 501)
Input: 3,3
Output: III, IX, XI, LV, XC, CII, CX, CCI, CCC, DII, DX, DCI, DCC
(note that IIC, and IID are not valid numbers. DD (1000) is also not a valid number, as the correct numeral is M) The value of these numbers (in order) is: 3, 9, 11, 55, 90, 102, 110, 201, 300, 502, 510, and 601)
This is a usual code-golf, and needless to say, I'm interested to see how golf languages implement roman numeral counting rules. Best of luck!
1Would you be able to add the counting rules? – Jonathan Allan – 2019-11-01T20:54:41.613
+1 Looks interesting – Poke – 2019-11-01T21:00:25.923
2Well written but upvoted mainly for sheer oddness of the challenge. – Jonah – 2019-11-01T23:45:53.777
The last test case appears to be missing
DCC
. I wouldn't mind answering this question if it stuck to standard Roman numerals, where e.g. the last test case would only beIII IX XI LV XC CII CX CCI CCC CDI DII DX DCI DCC
. – Neil – 2019-11-01T23:56:44.520Because 45 is written as
XLV
instead. – Neil – 2019-11-01T23:58:17.863@Neil My Bad. I've fixed it – tuskiomi – 2019-11-02T00:03:07.303
5
IC
,ID
are not valid roman numerals. – JBernardo – 2019-11-02T03:04:43.4571https://projecteuler.net/about=roman_numerals – HiddenBabel – 2019-11-02T03:17:27.973
I think the last two answers should be
2,2 => II X CI CC CD DI DC
and3,3 => III IX XI LV XC CII CX CCI CCC CDI DII DX DCI DCC
as IC and ID are not a valid roman numbers but CDI=401 is. Otherwise, this was a great puzzle. – Kjetil S. – 2019-11-02T13:03:45.087How exactly does an L intersect the bottom line twice? – randomdude999 – 2019-11-03T20:09:03.760