Roman numerals/Encode: Difference between revisions
Content added Content deleted
(RPL: cleanup) |
(RPL: cleanup) |
||
Line 6,753: | Line 6,753: | ||
clean stack |
clean stack |
||
|} |
|||
===Alternate version=== |
|||
{| class="wikitable" |
|||
! RPL code |
|||
! Comment |
|||
|- |
|||
| |
|||
≪ '''IF''' DUP 5000 < '''THEN''' |
|||
{ "IIIVIIIX" "XXXLXXXC" "CCCDCCCM" } |
|||
{ 11 21 31 43 44 54 64 74 87 88 } → rom args |
|||
≪ "" SWAP |
|||
1 3 '''FOR''' j |
|||
10 MOD LAST / IP |
|||
'''IF''' SWAP '''THEN''' |
|||
args LAST GET 10 MOD LAST / IP |
|||
rom j GET ROT ROT SUB ROT + SWAP '''END''' |
|||
'''NEXT''' ≫ |
|||
'''WHILE''' DUP '''REPEAT''' 1 - "M" ROT + SWAP '''END''' |
|||
DROP '''END''' |
|||
≫ ''''→ROM'''' STO |
|||
| |
|||
'''→ROM''' ''( n -- "M..CXVI" ) '' |
|||
collapsed Roman digits |
|||
10 arguments to extract Roman digits |
|||
initialize stack |
|||
process units to hundreds |
|||
divmod(n,10) |
|||
if last digit ≠ 0 then |
|||
get extraction arguments |
|||
extract Roman digit |
|||
add thousands if any |
|||
clean stack |
|||
|} |
|} |
||