- Code Golf Hole Two - Roman Numeral to Decimal Converter
- 08 Jun 2019 11:39:37 am
- Last edited by LogicalJoe on 18 Jun 2019 10:01:20 am; edited 9 times in total
Because so many people have expressed interest in another code golf to follow up my first, I am proud to present:
LJ Open: The Second Hole - Roman Numeral to Decimal Converter.
This program should take a roman numeral in a string in Ans and return the Decimal (Base 10) equivalent in Ans. Because this program does not output anything during execution, it is an "invisible" program. This program only needs to accept the traditional Roman Numerals (I V X L C D M), output for non-numerals can vary (be undefined) and invalid sequences can also output whatever you like (i.e. IIII or VIV).
Here's how it should look on the home:
Code:
I quite enjoyed golfing this myself, and I can provide some bloated example code:
Code:
Size: The program's size is measured as:
Code:
You can read the Roman Numeral wikipedia here.
The poll will be open for a week. I will post my solution as soon as someone beats it or the week is up
Good luck!
Current Results:
lirtosiast: 54
PT_: 59
Weregoose: 61
commandblockguy: 65 | 263
kg583: 71
LogicalJoe: 76
MateoConLechuga: 244
LJ Open: The Second Hole - Roman Numeral to Decimal Converter.
This program should take a roman numeral in a string in Ans and return the Decimal (Base 10) equivalent in Ans. Because this program does not output anything during execution, it is an "invisible" program. This program only needs to accept the traditional Roman Numerals (I V X L C D M), output for non-numerals can vary (be undefined) and invalid sequences can also output whatever you like (i.e. IIII or VIV).
Here's how it should look on the home:
Code:
"VI":prgmR[:Ans]
6
I quite enjoyed golfing this myself, and I can provide some bloated example code:
Code:
seq(inString("IVXLCDM",sub(Ans+".",A,1)),A,1,1+length(Ans->L1
{1,5,10,50,100,500,1000->L2
sum(seq(L2(L1(X)),X,1,dim(L1)-1->B
For(A,1,dim(L1)-1
If L1(A+1)>L1(A
B-2L2(L1(A->B
End
B
Restrictions wrote:
Restricted tokens: prgm
Can only accept the Ans variable in roman-numeral format
Can only accept the Ans variable in roman-numeral format
Size: The program's size is measured as:
Code:
on-calc-size - 9 - length(name)
You can read the Roman Numeral wikipedia here.
The poll will be open for a week. I will post my solution as soon as someone beats it or the week is up
Good luck!
Current Results:
lirtosiast: 54
PT_: 59
Weregoose: 61
commandblockguy: 65 | 263
kg583: 71
LogicalJoe: 76
MateoConLechuga: 244