DEV Community

Cover image for Ancient computer science: Let's build a Roman numeral converter from scratch πŸΊπŸ“œ

Ancient computer science: Let's build a Roman numeral converter from scratch πŸΊπŸ“œ

Pascal Thormeier on October 04, 2021

Today, we're going time travelling! Let's go back to the year CCXVII, so 217, all the way to the iron age: The Roman empire. But today we're not e...
Collapse
 
grahamthedev profile image
GrahamTheDev

Well I can't believe it, but I spent ages teaching people how to write roman numerals and they still forget 1, 1000, 51, 6 and 500.

IM LIVID! πŸ˜‰πŸ€£

Seriously though, fun little project, I enjoyed the writeup on it too! ❀

Collapse
 
thormeier profile image
Pascal Thormeier

Awesome, didn't know that one! So glad you liked it! :) I'm reading some Terry Pratchet currently and stumbled upon differen roman numbers in character's names and thought "why not explain how they work and make a tutorial about that"

Collapse
 
dodothedev profile image
Dominic Ross

Not to be "that guy", but western numbers are not Arabian. They actually came from India. They were called Arabic numbers because at the time they made their way to the western world (modern day Europe), the crusades were happening and that's where we got the knowledge of "Arabic" numerals. They made their way to Arabia from trade links between them and India via the silk road.

I'm no expert, but I got this from a podcast called "you're dead to me" on BBC about history. Very interesting (no, I'm not affiliated 🀣)

Collapse
 
thormeier profile image
Pascal Thormeier

After doing a bit of research myself, I conclude that I should've done my research better before hitting that "Publish" button... πŸ˜… You're absolutely right, will correct that right away, thank you!

Collapse
 
thormeier profile image
Pascal Thormeier

Scratched the original explanation and added the correct one with credits to you. I really didn't do my research good enough there and ended up with this false piece of info. Thank you for pointing that out, helps a great deal to improve the quality of my posts πŸ™‚

Thread Thread
 
dodothedev profile image
Dominic Ross

Didn't mean to be a detractor from a very good written article. I only learnt a couple of weeks ago myself from that podcast and had always thought they were Arabic too. Just spreading the useless information I pickup so easily (just wish I could do the same with coding πŸ˜‚).

Collapse
 
alexmitchelldev profile image
Alex Mitchell • Edited

Thank you for this solution Pascal!

I am a new programmer/developer and really enjoyed working through your solution, I have added it to my list to go back through the code to get a deeper understanding.

I really liked how you reversed digits then used i from the for loop to calculate powerOf10, nice!

Cheers,

Alex :)

Collapse
 
thormeier profile image
Pascal Thormeier

You're very welcome, so glad my post helped you. πŸ˜€ If you have any questions about it, please feel free to ask, I'm always happy to help!

Collapse
 
jayjeckel profile image
Jay Jeckel

Very fun puzzle and a great article as well!

Interesting additional information, the rules that we consider normal for Roman numerals are actually a fairly modern invention. The simplest example is that IIII was often used instead of IV, and still is in some cases such as certain clocks. There were also cases of multiple leading subtractive symbols being used, such as IIXX for 18 instead of XVIII, due to how they spoke, in this case "two from twenty".

Such an interesting problem, seems simple on the surface, but the deeper you dig the more edge cases their are.

Collapse
 
thormeier profile image
Pascal Thormeier

Thank you very much, glad you enjoyed it! I didn't know that, thank you! The code in the article is not really capable of handling, for example, the IIXX case, even though it probably wouldn't take much to cover that, too. It's something I really like about our number system today: There's only ever one way to write a number (that is, if you don't count mathematical expressions or complex numbers...)

(Sorry for the late reply)

Collapse
 
thormeier profile image
Pascal Thormeier

Thank you for your inputs, very valuable and they do improve the performance! Glad you liked the post. :) It's true that I could've used the array methods like reduce and the spread operator more often. I omitted them on purpose though, as they add complexity for the reader, especially if they're not familiar with them, so they can concentrate on the functionality of the algorithm.

Collapse
 
lisaironcutter profile image
Lisa Tagliaferri

Always great to see Ancient Rome and Computer Science together ❀

Collapse
 
thormeier profile image
Pascal Thormeier

I'm sure there are many more concepts in ancient mathematics, engineering, astronomy or even economics one could rebuild with JS or any other language! Is there any topic you yourself would be particularly interested in?

(Sorry for the late reply)