Roman numerals

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Roman numerals

Postby Roger|Dyalog on Sat Apr 25, 2020 12:29 am

rfd produces Roman numerals from decimals, and dfr decimals from Roman numerals.

      dfr←{(¯1*i<1↓i,¯1) +.× 1 5 10 50 100 500 1000[i←'IVXLCDM'⍳⍵]}

r100← 1↓¨ ' ' (=⊂⊢) ' C CC CCC CD D DC DCC DCCC CM'
r10 ← 1↓¨ ' ' (=⊂⊢) ' X XX XXX XL L LX LXX LXXX XC'
r1 ← 1↓¨ ' ' (=⊂⊢) ' I II III IV V VI VII VIII IX'
R1000← , r100 ∘., r10 ∘., r1

rfd← {('M' ⍴⍨ ⌊⍵÷1000), R1000 ⊃⍨ 1000|⍵}

See the final note in the APL Chat Forum post Enumerating Permutations on the names of the functions: dfr (decimal from Roman) and not rtd (Roman to decimal). Likewise rfd.

A few examples:

      rfd 12345
MMMMMMMMMMMMCCCXLV
dfr rfd 12345
12345

rfd 123
CXXIII
dfr 'CXXIII'
123

dfr 'CIVIC' ⍝ hmmm ...
203
rfd 203
CCIII

rfd 0

dfr ''
0

Now the point of this post :-), the multiplication table for Roman numerals:

      rfd¨ ∘.×⍨ 1+⍳10
┌────┬─────┬─────┬──────┬────┬──────┬──────┬──────┬─────┬────┐
│I │II │III │IV │V │VI │VII │VIII │IX │X │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│II │IV │VI │VIII │X │XII │XIV │XVI │XVIII│XX │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│III │VI │IX │XII │XV │XVIII │XXI │XXIV │XXVII│XXX │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│IV │VIII │XII │XVI │XX │XXIV │XXVIII│XXXII │XXXVI│XL │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│V │X │XV │XX │XXV │XXX │XXXV │XL │XLV │L │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│VI │XII │XVIII│XXIV │XXX │XXXVI │XLII │XLVIII│LIV │LX │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│VII │XIV │XXI │XXVIII│XXXV│XLII │XLIX │LVI │LXIII│LXX │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│VIII│XVI │XXIV │XXXII │XL │XLVIII│LVI │LXIV │LXXII│LXXX│
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│IX │XVIII│XXVII│XXXVI │XLV │LIV │LXIII │LXXII │LXXXI│XC │
├────┼─────┼─────┼──────┼────┼──────┼──────┼──────┼─────┼────┤
│X │XX │XXX │XL │L │LX │LXX │LXXX │XC │C │
└────┴─────┴─────┴──────┴────┴──────┴──────┴──────┴─────┴────┘

(Misalignments in the display are due to defects in the APL Chat Forum software.)

Translated from the J Wiki essay Roman Numerals, 2005-11-02.
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Roman numerals

Postby jayfoad on Mon May 04, 2020 1:59 pm

Quod vide: http://dfns.dyalog.com/n_roman.htm (mensa mvltiplicandorvm)
jayfoad
 
Posts: 5
Joined: Wed May 29, 2019 1:51 pm


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest