1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Varvara68 [4.7K]
4 years ago
7

Define a romanNumberToInt function that converts a RomanNumber value, which is a list of Roman digits, into an integer. Hints: -

Assume the Roman number representation is valid. - Use recursion to sum up number in romanNumber because it is a list. - Use pattern guards to manage case when digits come in reverse order, e.g. IX, IV.
Computers and Technology
1 answer:
USPshnik [31]4 years ago
6 0

Answer:

Check the explanation

Explanation:

type RomanDigit = int

type RomanNumeral = RomanDigit list

type RomanDigit = I | V | X | L | C | D | M

type RomanNumeral = RomanNumeral of RomanDigit list

/// Converting a single RomanDigits to an integers here

let digitToInt =

function

| I -> 1

| V -> 5

| X -> 10

| L -> 50

| C -> 100

| D -> 500

| M -> 1000

// testing here

I |> digitToInt

V |> digitToInt

M |> digitToInt

let rec digitsToInt = function

 

// empty is notified by using 0

| [] -> 0

// special case when a smaller comes before larger

// convert both digits and add the difference to the sum

// Example: "IV" and "CM"

| smaller::larger::ns when smaller < larger -> (digitToInt larger - digitToInt smaller) + digitsToInt ns

// otherwise convert the digit and add to the sum

| digit::ns -> digitToInt digit + digitsToInt ns

// tests

[I;I;I;I] |> digitsToInt

[I;V] |> digitsToInt

[V;I] |> digitsToInt

[I;X] |> digitsToInt

[M;C;M;L;X;X;I;X] |> digitsToInt // that is 1979

[M;C;M;X;L;I;V] |> digitsToInt // that is 1944

/// converts a RomanNumeral to an integer

let toInt (RomanNumeral digits) = digitsToInt digits

// test

let x = RomanNumeral [I;I;I;I]

x |> toInt

let x = RomanNumeral [M;C;M;L;X;X;I;X]

x |> toInt

You might be interested in
Why laptop computer is called micro computer?​
Eduardwww [97]

Answer:

A lot top is a microcomputer because Michael computer has all the devices that you can use

3 0
4 years ago
Given the following array definition, write a constant declaration named ArraySize that automatically calculates the size in byt
Rina8888 [55]

Answer:

ArraySize = ($ - newArray)

Explanation:

Given

Array name: newArray

Type: DWORD

Required

The size of the array in bytes

The following formula is used to calculate the size of an array in assembly language.

Variable = ($-Array name)

So, we have:

ArraySize = ($ - newArray)

<em>Where ArraySize is the variable that holds the size of newArray (in bytes)</em>

8 0
3 years ago
Three uses for Auto Formatting in Word 2016.
sdas [7]

Answer

  1. Auto Numbering and billeting
  2. Auto paragraphing and  indenting
  3. automatically super-scripting and sub-scripting

Explanation

Auto formatting is a software commonly found in word processor such as word 2016 and it is designed to automatically change the appearance of the text. In numbering and bulletin this helps by generating numbers automatically and it makes it easier for the user when typing for does not need to keep on going through the menu bar for numbering. Same case on paragraphing and indenting.  Auto formatting also helps in automatically generating the superscript and subscript. This helps in saving time and also producing a decent and an appealing  work or document.

3 0
3 years ago
How many errors are in the following formula?
finlep [7]

there are about two errors in the formula


4 0
3 years ago
What are the columns in a Microsoft Access table called?
givi [52]

Answer:

Field. In Access, columns are referred to as fields. When you organize your data by entering it into different fields, you are organizing it by type.

3 0
3 years ago
Other questions:
  • Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output tho
    9·1 answer
  • There is no reason to study the works of famous photographers because they will make you less creative.
    5·2 answers
  • What the heck is a motherboard and why is my computer not working when i take it out
    14·1 answer
  • Split a string by string.
    6·1 answer
  • Splunk knows where to break the event, where the time stamp is located and how to automatically create field value pairs using t
    7·1 answer
  • Create detailed pseudocode for a program that calculates how many days are left until Christmas, when given as an input how many
    15·1 answer
  • ILL GIVE BRAINLIEST IMMEDIATELY PLEASE HELP
    10·2 answers
  • WAp to input the radius and print<br> the area of circle
    15·1 answer
  • A program similar to mtr, ____, is available as a command-line utility in Windows operating systems.
    12·1 answer
  • many police departments coordinate youth-oriented programs as part of their prevention efforts. which of the following is not an
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!