Roman numerals/Encode: Difference between revisions
Improved RPL code with comments
(add RPL) |
(Improved RPL code with comments) |
||
Line 6,662:
</syntaxhighlight>
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
≪ '''IF''' DUP 5000 < '''THEN'''▼
! RPL code
! Comment
'''WHILE''' DUP 1 ≥ '''REPEAT''' ▼
|-
1 - SWAP "M" + SWAP '''END''' ▼
|
1 3 '''FOR''' j ▼
▲ ≪ '''IF''' DUP 5000 < '''THEN'''
10 * ▼
{ "IIIVIIIX"
≪ ""
1 3 '''FOR'''
'''
≫ '➜ROM' STO▼
DROP '''END'''
|
'''→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
|}
=={{header|Ruby}}==
|