How to resolve the algorithm Roman numerals/Encode step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Roman numerals/Encode step by step in the Quackery programming language

Table of Contents

Problem Statement

Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero.

In Roman numerals:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Roman numerals/Encode step by step in the Quackery programming language

Source code in the quackery programming language

  [ $ "" 
    swap 1000 /mod $ "M" rot of rot swap join swap
    dup   900 < not if [ 900 - dip [ $ "CM" join ] ]
    dup   500 < not if [ 500 - dip [ $  "D" join ] ]
    dup   400 < not if [ 400 - dip [ $ "CD" join ] ]
          100 /mod $ "C" rot of rot swap join swap
    dup    90 < not if [  90 - dip [ $ "XC" join ] ]
    dup    50 < not if [  50 - dip [ $  "L" join ] ]
    dup    40 < not if [  40 - dip [ $ "XL" join ] ]
           10 /mod $ "X" rot of rot swap join swap
    dup     9 < not if [   9 - dip [ $ "IX" join ] ]
    dup     5 < not if [   5 - dip [ $  "V" join ] ]
    dup     4 < not if [   4 - dip [ $ "IV" join ] ]
    $ "I" swap of join ] 
                              is ->roman ( n --> $ )

  1990 dup echo say " = " ->roman echo$ cr
  2008 dup echo say " = " ->roman echo$ cr
  1666 dup echo say " = " ->roman echo$ cr

  

You may also check:How to resolve the algorithm Sum of squares step by step in the bc programming language
You may also check:How to resolve the algorithm String concatenation step by step in the HicEst programming language
You may also check:How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Nim programming language
You may also check:How to resolve the algorithm Subleq step by step in the Perl programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the 6502 Assembly programming language