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
What do these terms have in common? google, yahoo!, bing they are important books. they are internet search engines. they are wo
Vlada [557]
They are Internet search engines.
7 0
4 years ago
The _____ is a blinking vertical line that indicates where the next typed character will appear. scroll box sheet tab insertion
e-lub [12.9K]
Cursor is the perfect answer. but  as per your options , insertion point could be the answer
3 0
3 years ago
Please help me asapppp!​
I am Lyosha [343]

Answer:

1.  Formula is A2 : A9 = COUNT( A2: A9 ) = 8

2. Formula is SUM( A2: A9 ) = 36

3. Formula is B2 : B9 = COUNT( B2: B9) = 8

4. Formula is  MAX( C2: C9) = 5

5. Formula is MIN( C4: C8) = 3

6. Formula is SUM( C5 - C6) = 0

7. Formula is AVERAGE( C2: C9) = 4

Explanation: Have a nice day!✌️

6 0
3 years ago
One of the files you should now have in your fileAsst directory is TweedleDee/hatter.txt. Suppose that you wished to copy that f
Paha777 [63]

Answer:

cp /path/to/source.txt .

is the general format of copying a file to the current directory

cp ~/UnixCourse/fileAsst/TweedleDee/hatter.txt .

You can refer to the current directory with a dot (.)

Explanation:

First, we would like to delete all files in our current directory (commandsAsst directory). To delete the files inside the directory, we would run the following command:

rm -r commandsAsst/*

This command delete the files recursively. Usually, the command for deleting is rm -r. The operator * run rm -r on every file or directory within commandsAsst.

5 0
3 years ago
Brad leaves an iPod at Computer Sales &amp; Repair (CSR) to have the battery replaced. CSR sells the iPod to Doris, who does not
katrin2010 [14]
I think the answer is d. I could be wrong.
6 0
4 years ago
Other questions:
  • Part 2: students and courses, part 1  java review you may use an ide or a text editor, but i will test this by compiling and ru
    6·1 answer
  • Which statement is the best description of a value proposition?
    7·2 answers
  • Write a C++ program that will ask the user for the name of a data file.
    11·1 answer
  • Contrast the performance of the three techniques for allocating disk blocks (contiguous, linked, and indexed) for both sequentia
    13·1 answer
  • True or false questions. If a statement is false, you must explain the reason why it is false: a). Suppose that TCP is being run
    12·2 answers
  • The automatic number of worksheets that appear when you open a blank Excel workbook is ? 1.One 2.Three 3.Six 4.Ten
    8·1 answer
  • Create a goal seek analysis to determine what the price should be to generate demand of 2,625,000 tablets given that the supplie
    10·1 answer
  • Which tool should be used to verify the compatibility of an application run on Windows 10?
    7·1 answer
  • Iaz005<br> plz make a new zoom
    8·2 answers
  • What does a companys code of ehtics cover
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!