Addition with Roman Numerals

For a little bit I’ve been interested in how people do equivalent things with largely different systems. For instance, when we add in roman numerals and arabic numerals, we’re representing the same thing: 1 thing and another thing is two things. The algorithm we use, and presumably the way we think of it, are hugely different, though.

I coded up a quick script that can take two roman numerals and add them. It only supports the most naive form — you can’t use subtractives like IX, only VIIII, and you can’t pass in V-with-a-bar-on-top, only MMMMM.

The rules are:

  • Concatenate the two numbers:
    • VII and XVI become VIIXVI
  • Sort them from M -> I
    • VIIXVI becomes XVVIII
  • Combine any like values into larger numerals
    • XVVIII becomes XXIII

You can see the code here.

The post that told me how it all worked is here.