Defining The Numerals

To start off with, I declared a few constants. The first two being the fundamental set of characters for our numerals:



constant

constant @letter-pairs = reverse # … the following code constant @letters = ｢IVXLCDM｣.comb;constant @overlines = "\c[combining overline]", "\c[combining double overline]"; # These represent x 1000 and x 1000000constant @letter-pairs = reverse # … the following code

These constants are then used to give us a list of all of our numerals:

We start of by taking our I from the list. Following that, we create a list of three groups of letters:



# (I V X L C D M)(I̅ V̅ X̅ L̅ C̅ D̅ M̅)(I̿ V̿ X̿ L̿ C̿ D̿ M̿) @letters , | @overlines .map( @letters X~ * )# (I V X L C D M)(I̅ V̅ X̅ L̅ C̅ D̅ M̅)(I̿ V̿ X̿ L̿ C̿ D̿ M̿)

We split each of these into overlapping groups of three using rotor , and then use the elements from each of those lists to take our numerals:

.rotor(3 => -1)

# ((I V X) (X L C) (C D M))

# .[0,1], .[1], .[0,2], .[2] on each group gives us IV, V, IX, X etc

Now we want to assign all of these numerals their appropriate values. We do that using the following sequence:

1, |( * X* 4, 5, 9, 10 ) … ∞

What this sequence does is take the 1 and gives us that multiplied by 4, 5, 9 and 10. With the 10 now on the end of the list, the sequence is repeated, giving us 40, 50, 90 and 100. This continues ad infinitum for as many numbers as we need.

Taking our list of numerals and zipping ( z=> ) them with the numbers gives us the list of pairs we’ll be using: