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
The buttons on a specific tab are organized into logical Ribbons. <br> T<br> F
NeTakaya
I believe the answer would be true
8 0
3 years ago
Read 2 more answers
What does N represent when analyzing algorithms?
Mademuasel [1]

Answer: "N" is considered as the size of the input that is being given in the algorithm.

Explanation: During a problem solving process , a algorithm is used to analyze the problem . Many function and  steps are to be taken care of while analyzing algorithm. Among analyzing step, input is also given which is usually zero more than that . An input has a certain size which is given by the initial "N".  The input size defines the length of the string for the input.

4 0
3 years ago
Discuss how the user-designer communications gap can cause a good project to go bad.
Mila [183]
This gap between user-designer communications <span>can cause a good project to go bad i</span>f the user is not able to process what is required to be fixed in order for the project to run smoothly. The user may have one way of fixing something while the designer has another. In this case, the designer understands how the project fully works while the user does not and this may end up compromising the whole project.

The law that “designers are not users” and “users are not designers” should always be followed.




3 0
3 years ago
Riodic Table
Ksenya-84 [330]

Answer:

riodic Table

A museum wants to store their valuable documents in cases that contain a gas that will protect the documents.

She should not choose one of the other gases because they are too

The museum director should choose

Explanation:

I didn't understand

8 0
3 years ago
Why do we need multitasking functionality in an Operating System?
Leokris [45]

Answer:

Multitasking is a process in which we do multiple task at a time.    

In computing system, multitasking is the concept of performing different types of multiple task and process over a certain period of time by executing simultaneously.

Operating system basically allow various task to run simultaneously by the user. In an operating system, each task consume storage system and all the other resources.

Multitasking function facilitate memory isolation in the processor and also supported different levels of security system in the operating system. For example, "a programmer working on any program in a system and as well as listening the music then, it perform multiple task at the same time".

7 0
2 years ago
Other questions:
  • Which of the following is another name for cinematographers? (Select all that apply). lighting specialists production manager di
    8·1 answer
  • Liz will use a CD-R compact disk to write to more than once. Carlo will use a CD-RW compact disk to write to more than once. Who
    8·2 answers
  • What happens when the computer is thrashing? quizzlet?
    12·1 answer
  • On computer X, a nonpipelined instruction execution would require 12 ns. A pipelined implementation uses 6 equal-length stages o
    9·1 answer
  • 1. JAVA Create one method to do the following expressions. Given the following declarations, what is the result of each of the e
    13·1 answer
  • Not providing guarding or fall protection for workers on a 25-foot scaffold. The resulting fall would most likely end in death,
    6·1 answer
  • The major difference between a template and another document is in _____.
    7·1 answer
  • Who is your favorite person from squid game?
    13·2 answers
  • Jade has to create a workbook for storing information of students participating in the annual state-level sports competition. Th
    5·1 answer
  • What is a word processor write any five important features of word processor?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!