Challenge: Roman numerals! | SoloLearn: Learn to code for FREE!

+8

Challenge: Roman numerals!

Need to write a function that takes arabic numerals and return the roman numerals. Roman numerals: I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000 Example: 10 -> X 6 -> VI 76 -> LXXVI 499 -> CDXCIX ... Precondition: Input: integer (0 < input < 3999) Output: string Please set the language in comment!!! If you resolve this task set plus!!!

12/16/2017 1:19:27 PM

Сергей Козловский

14 Answers

New Answer

+18

Inline assembly: https://code.sololearn.com/cXqZjdjBKqGu/?ref=app

+15

Onliner 😊 https://code.sololearn.com/c95Y62c4p1dV/?ref=app

+7

https://code.sololearn.com/cLOi9wpPOJjF/?ref=app Works between 1-4000000(excluded)

+6

https://code.sololearn.com/c2E37k10vS2y/?ref=app

+5

https://code.sololearn.com/cSl9R9bLoLcd/?ref=app

+4

https://code.sololearn.com/co4RsqM8ryVm/?ref=app

+4

My try here https://code.sololearn.com/c1T38DE98C37/?ref=app

+4

Here is my attempt in Python: https://code.sololearn.com/c4CctDZ2Iiik/#py

+2

My first code ever, in Python 3: https://code.sololearn.com/cF88oyMa3W15/#py If you have any comments, let me know!

+1

c# https://code.sololearn.com/c4lgtSJHyy51/?ref=app

+1

My try in PHP : https://code.sololearn.com/wxN8Wu6W58Cm/#php I hope you'll understand my technical comment in english ;) I notice that Roman numerals work by pairs "unit" and "five" for every decimal in base10 (I and V, X and L, ...). I use base5 conversion for every base10 position. + a test when last number (unit) is 4 in base5 : in that case I use 1 unit before the next letter depending on the next col in base5 (0 or 1) thus "five" or next unit. The second function is only for formating purpose while testing.

+1

My try on python. 1. a integer to roman numeral, work between 0 to 3999. https://code.sololearn.com/caBR7zasyKVz/#py 2. roman numeral convert to integer. https://code.sololearn.com/c9fmB9cIaS3Q/#py

0

Very quickly?! You did that before?

0

tagged