Ask HN: Teach me something new
Arithmetic with Roman numerals.<p>You often hear that it was next to impossible to calculate with Roman numerals. That&#x27;s not true at all. People developed a very ingenious scheme to do additions and multiplications using pebbles. Since the word for pebble in Latin is calculus, we now call calculus calculus.<p>How did it go? You represented the digits of a number by a pebble. You drew some lines in the sand, some rows and columns. The rows represented the digit magnitude (I, V, X, etc). The columns were for the operands. Two columns for a number. Why two? Because Roman numerals sometimes use negative digits.<p>Let&#x27;s see a concrete example. You want to do the addition 28+44. That is XXVIII + XLIV.<p>You first draw the lines and put the pebbles in the corresponding squares. Note that XLIV has two negative digits (44 = XLIV = -10 + 50 -1 + 5). So the pebble for 10 and the one for 1 are put on the left side.<p>The first number does not have any negative digits, so no pebbles in its left column.<p><pre><code>  ———————————————————————————————
  L    |        ||       |  o
  X    |   oo   ||   o   |
  ——————————————————————————————— 
  V    |    o   ||       |  o 
  I    |  ooo   ||   o   |
  ———————————————————————————————
</code></pre>
So, now that we set the pebbles, we need to do the calculation. We can do it in many ways. Let&#x27;s start by first canceling the digits that can be canceled: a positive 10 pebble with a negative 10 pebble, and a positive 1 pebble with a negative 1 pebble. The table looks now like this:<p><pre><code>  ——————————————————————————————— 
  L   |        ||       |  o
  X   |   o    ||       |
  ——————————————————————————————— 
  V   |    o   ||       |  o 
  I   |   oo   ||       |
  ———————————————————————————————
</code></pre>
At this point we reduced the initial addition 28 + 44 (XXVIII + XLIV) to the equivalent one XVII + LV ( 17 + 55).<p>Now we just move the pebbles from the fourth column to the second column.<p><pre><code>  ——————————————————————————————— 
  L   |   o    ||       |   
  X   |   o    ||       |
  ——————————————————————————————— 
  V   |   oo   ||       |   
  I   |   oo   ||       |
  ———————————————————————————————
</code></pre>
We are almost done. We got the result as LXVVII. But this is not a valid Roman numeral, we need to do the simplification VV = X. We remove the two 5-pebbles and add a 10-pebble. Oh, and let&#x27;s get rid of the last 2 columns.<p><pre><code>  ————————————————
  L  |   o      || 
  X  |   oo     ||  
  ————————————————
  V  |          ||   
  I  |   oo     ||   
  ————————————————
</code></pre>
So now our final result, in correct form, is LXXII, or 72.<p>Multiplication can be also performed, and it&#x27;s quite a lot of fun. I&#x27;ll explain it in the post below.