Post Reply 
(49G) Arabic to Roman
01-21-2016, 10:38 AM (This post was last modified: 06-15-2017 01:46 PM by Gene.)
Post: #1
(49G) Arabic to Roman
A programme to convert an Arabic decimal integer in stack level 1 to its Roman representation in stack level 1.

The programme is a translation from the Prime programme here:

http://www.hpmuseum.org/forum/thread-5536.html

written by Didier Lachieze, thanks to him for the insightful analysis.

Code:

::
  CK1&Dispatch
  BINT1
  ::
    DUP
    %0>=
    SWAP
    %ABSCOERCE
    ZEROZEROZERO
    FPTR2 ^3LAMBIND
    {
      "M"
      "D"
      "C"
      "L"
      "X"
      "V"
      "I"
    }
    {
      # 3E8
      # 1F4
      BINT100
      BINT50
      BINT10
      BINT5
      BINT1
      BINT0
      BINT0
    }
    NULL$
    BINT8
    ONE_DO
    OVERINDEX@
    NTHCOMPDROP
    2PUTLAM
    BEGIN
    4PICK
    2GETLAM
    #>=_
    WHILE
    ::
      3PICK
      INDEX@
      NTHCOMPDROP
      &$
      4ROLL
      2GETLAM
      #-
      4UNROLL
    ;
    REPEAT
    INDEX@
    DUP
    BINT2
    #/
    DROP
    #+
    #1+
    DUP1PUTLAM_
    3PICKSWAP
    NTHCOMPDROP
    3PUTLAM
    4PICK
    2GETLAM
    3GETLAM
    #-
    #>=_
    IT
    ::
      3PICK
      1GETLAM
      NTHCOMPDROP
      &$
      3PICK
      INDEX@
      NTHCOMPDROP
      &$
      4ROLL
      2GETLAM
      #-
      3GETLAM
      #+
      4UNROLL
    ;
    LOOP
    ABND
    5UNROLL
    3DROP
    ?SEMI
    CHR_-
    >H$
  ;
;
Find all posts by this user
Quote this message in a reply
Post Reply 




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