Post Reply 
(42S) Roman to Arabic Representation
05-14-2020, 08:56 AM
Post: #10
RE: (42S) Roman to Arabic Representation
Making use of a 13x2 matrix "RN":
[[ 1000 77 ]
[ 900 "CM" ]
[ 500 68 ]
[ 400 "CD" ]
[ 100 67 ]
[ 90 "XC" ]
[ 50 76 ]
[ 40 "XL" ]
[ 10 88 ]
[ 9 "IX" ]
[ 5 86 ]
[ 4 "IV" ]
[ 1 73 ]]

Both encodings can be written as follows:

Code:
00 { 82-Byte Prgm }
01▸LBL "→ROM"
02 ENTER
03 EDITN "RN"
04▸LBL 02
05 X>Y?
06 GTO 00
07 STO- ST Y
08 →
09 XTOA
10 ←
11 GTO 02
12▸LBL 00
13 ↓
14 FC? 76
15 GTO 02
16 EXITALL
17 RTN
18▸LBL "→ARB"
19 INDEX "RN"
20 CLST
21 ALENG
22 X<> ST Z
23▸LBL 03
24 ATOX
25 XTOA
26 [FIND]
27 X=0?
28 ASTO ST Z
29 J-
30 CLX
31 RCLEL
32 X<>Y
33 X<Y?
34 +/-
35 STO+ ST Z
36 R↓
37 DSE ST Z
38 GTO 03
39 +
40 EXITALL
41 END

The →ROM routine appends the Roman numerals to the Alpha register; just add a CLA at the beginning and an AVIEW at the end if you want to see single results.
The →ARB routine (a copy of yours, Gerald, but using the RN matrix instead) has a rudimentary error check: when it encounters an unknown character it produces an "Alpha Data is Invalid" message.

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (42S) Roman to Arabic Representation - Werner - 05-14-2020 08:56 AM



User(s) browsing this thread: 2 Guest(s)