- Code Golf: Decimal to Roman Numeral Converter
- 10 Jun 2019 06:37:22 pm
- Last edited by lirtosiast on 11 Jun 2019 06:34:52 pm; edited 6 times in total
Following up on LogicalJoe's challenge, this is the reverse operation.
Write a program that takes an integer 1 ≤ N ≤ 3999 from Ans, and converts it to Roman Numerals, giving the output as a string in Ans. Invalid inputs may produce undefined behavior.
Your byte count is the number of bytes of code, i.e. (program size) - 9 - (name length).
Reference implementation (172 bytes):
Code:
Test cases:
Code:
Note that your program must produce results for all 1 ≤ N ≤ 3999, not just the given test cases.
I will post my answer when someone beats it, or after a week or so. At the start of the contest, it's 96 bytes.
Results
lirtosiast/PT_/Mateo: 85
lirtosiast: 90
PT_/Mateo: 93
Weregoose: 108
Write a program that takes an integer 1 ≤ N ≤ 3999 from Ans, and converts it to Roman Numerals, giving the output as a string in Ans. Invalid inputs may produce undefined behavior.
Your byte count is the number of bytes of code, i.e. (program size) - 9 - (name length).
Reference implementation (172 bytes):
Code:
Ans->N
".->Str1
"IIIVIIIX XXXLXXXC CCCDCCCM MMM->Str3
{1,1,1,3,4,4,4,4,7->|LSTART
{1,2,3,2,1,2,3,4,2->|LLEN
For(I,int(log(N)),0,~1
int(10fPart(N/10^(I+1->D
If D
Str1+sub(Str3,9I+|LSTART(D),|LLEN(D->Str1
End
sub(Str1,2,length(Str1)-1
Test cases:
Code:
1 -> I
78->LXXVIII
404 -> CDIV
999 -> CMXCIX
1000 -> M
2019 -> MMXIX
3456 -> MMMCDLVI
Note that your program must produce results for all 1 ≤ N ≤ 3999, not just the given test cases.
I will post my answer when someone beats it, or after a week or so. At the start of the contest, it's 96 bytes.
Results
lirtosiast/PT_/Mateo: 85
lirtosiast: 90
PT_/Mateo: 93
Weregoose: 108