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]
3 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]3 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
How to disable Fortinet?
Anni [7]

Answer:

Click on the start menu and go to the control panel. Video of the Day.

Click "Programs and Features" to launch the programs and features window.

Scroll down the window, click "Fortinet Antivirus," and then click the uninstall button.

Explanation:

8 0
2 years ago
Is backing up computer files done on the hard drive?
melomori [17]
Yes I believe so 

It should be acked up on the hard drive
7 0
3 years ago
Answer this blank:<br><br> Air enters through the mouth or nose, and travels through the _
Schach [20]
Respiratory system ?. Or esophagus?
5 0
3 years ago
Read 2 more answers
What are your thoughts on the last nintendo direct
allsm [11]

Answer:

I don't know? How do you feel about them?

Explanation:

5 0
2 years ago
Read 2 more answers
There is no need to schedule video calls ahead of time; they can be used the same way as
UNO [17]

Answer:

The answer to this question is "True".

Explanation:

The term video calling is part of communication. In this type of communication will be used in every place like house, office for video conferencing, etc. It was developed in 1968 by AT&T's Bell Labs. It works on internet.This type of calling we can face to face communicate means, we watch the person. In the video calling, there is no need for a schedule it is used as a phone call.  

6 0
3 years ago
Other questions:
  • When looking through the documentation for a specific class, you never actually see the source code for that class. Instead, you
    6·1 answer
  • (If the link is not working, search for "Veritasium Levitating Barbecue". At approximately the 2 minute mark, the screen shows 8
    9·1 answer
  • When using presentation aids A. make the aid available for the audience to look at throughout the speech. B. prepare to give you
    6·1 answer
  • Which part of a fax cover sheet helps the recipient verify the successful transmission of all the pages? A) REMARKS: be) TOTAL N
    7·2 answers
  • Which protocol do e-mail programs use to identify the file types of attached files?
    7·1 answer
  • What does media saturation mean?
    15·1 answer
  • What is the purpose of exporting your public key to the directory services server?
    11·1 answer
  • . Write a C++ Code to get a multiline statement Str1 from a user with a ‘$’ as return character (Hint:
    6·1 answer
  • Direction: using the data at the left, answer the questions that follows.​
    11·1 answer
  • Does any of yall play rob lox?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!