How to resolve the algorithm Roman numerals/Decode step by step in the Insitux programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Roman numerals/Decode step by step in the Insitux programming language

Table of Contents

Problem Statement

Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost decimal digit and skipping any 0s   (zeroes). 1990 is rendered as   MCMXC     (1000 = M,   900 = CM,   90 = XC)     and 2008 is rendered as   MMVIII       (2000 = MM,   8 = VIII). The Roman numeral for 1666,   MDCLXVI,   uses each letter in descending order.

Let's start with the solution:

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

Source code in the insitux programming language

(var numerals {"M" 1000 "D" 500 "C" 100 "L" 50 "X" 10 "V" 5 "I" 1})

; Approach A
(function ro->ar r
  (-> (reverse (upper-case r))
      (map numerals)
      (split-with val)
      (map (.. +0))
      (reduce @(((< % %1) + -)))))

; Approach B
(function ro->ar r 
  (-> (upper-case r) 
      (map numerals) 
     @(reduce (fn [sum lastv] curr [(+ sum curr ((< lastv curr) (* -2 lastv) 0)) curr]) [0 0]) 
      0))

(map ro->ar ["MDCLXVI" "MMMCMXCIX" "XLVIII" "MMVIII"])

  

You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the Scala programming language
You may also check:How to resolve the algorithm Shortest common supersequence step by step in the jq programming language
You may also check:How to resolve the algorithm Repeat step by step in the C# programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Racket programming language
You may also check:How to resolve the algorithm SHA-256 step by step in the Halon programming language