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
Blank text has a darker apperance than normal texts
sammy [17]
That's cool, I guess. What was the question?
4 0
3 years ago
2.13.4 Colorful Caterpillarhel ????
exis [7]

Answer:

sorry don't know :(8685

3 0
3 years ago
Think of all your favorite movies or games. Is their digital animation present? How do you think that it affected the movie or g
Mademuasel [1]
A ........................
7 0
3 years ago
Read 2 more answers
How does an ALU perform logical operations?
Naddik [55]

ALU perform logical operations by combining electrical signals with each other.

6 0
3 years ago
A method can not be made final until whole class is madefinal.TrueFalse
Blababa [14]

Answer:

True.

Explanation:

A method can not be made final until whole class is madefinal.

4 0
3 years ago
Other questions:
  • Calculated fields can be entered in queries. What row should you type a calculated field in?
    13·1 answer
  • A hub or ____ is a central point that connects several devices in a network together.
    11·1 answer
  • What are some characteristics of filtering junk email in Outlook 2016? Check all that apply.
    9·2 answers
  • The ________ Web, originally envisioned by Tim Berners-Lee, one of the founders of the Internet, is a set of design principles t
    15·1 answer
  • What field in a TCP segment is used to determine if an arriving data unit exactly matches the data unit sent by the source?]
    10·1 answer
  • Gloria is in her sophomore year of college and works part time. She has assignments saved on her home computer, her aunt's lapto
    6·2 answers
  • A 1000 elements array is used to store integers ascending order . The array is used to search binary search algorithm for the in
    14·1 answer
  • What is the output of the following program?
    5·1 answer
  • 1) ( IBADE - 2020)A legislação que regula o uso da Internet no Brasil por meio da previsão de princípios, garantias, direitos e
    9·1 answer
  • Meats ages hair and feathers all contain this monomer
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!