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 waterfall model and spiral model are variations of SDLC. Do some research to find out what they are and explain how these mo
Radda [10]

Waterfall model and spiral model are used in software development life cycle or SDLC. Any software development process follows one of these models depending on the type of software and the requirements of the customer.

Waterfall model

This model is called as sequential model since it works in stages. The output of first stage becomes the input of the second stage.

The errors of the first stage can be rectified only when it is completed. This is time consuming and makes the process lengthy. Stage 1 is completed before stage 2 begins.

The six stages involved in waterfall model are Requirement Gathering and analysis, System Design, Implementation, Integration and Testing, Deployment of system, and Maintenance.

Spiral model

This model is implemented in iterations. It is also called evolutionary model.  

Initially a prototype of the system is prepared. Then, it is followed by development of small parts of the system.

These smaller parts are then assembled to produce the final system.

The four stages which form the spiral model are Identification, Design, Development and Evaluation and Risk Analysis.

The differences between the two models are summarized below.

1. Waterfall model works in linear method. Spiral model follows evolutionary method.

2. Errors and risks are discovered/ rectified after the stage is over. Errors and risks are discovered/ rectified earlier.

3. Waterfall model is suitable for small projects. Spiral model is suitable for large projects.

4. Requirements identification and planning is the initial stage in the waterfall model. Requirements identification and planning is done when needed, in the spiral model.

5. Waterfall model allows little to no flexibility in the system. Spiral model allows flexibility in the system.

6. Low flexibility makes the waterfall model more risky. High flexibility makes the spiral model less risky.

7. Waterfall model, overall, takes less time since requirements are clear. Spiral model is implemented when the requirements of the system are not clear and become clear through prototypes.

8 0
3 years ago
Stay at least _____ behind the vehicle ahead of you at all times.
fenix001 [56]

Answer:

B 4 seconds

Explanation:

You should stay 4 seconds away from a vehicle at all times at the same speed as the other vehicle or vehicles.

6 0
2 years ago
Read 2 more answers
Mr. Stevens is the principal of a high school. Why might he want to export data from a database of students’ exam scores?
Anna007 [38]

I am not sure but I think that it is either the First option or the Third option but you would probably need more information.

7 0
2 years ago
Read 2 more answers
At your job, you often have to address letters to the customer support manager, Tyson Kajewski. The problem is that you are cons
krek1111 [17]
Input his name in the dictionary function, you can also copy the given name an paste as much as you need
5 0
3 years ago
After a system is released and the user base grows, the demands on the development and support team will ______.
otez555 [7]

After a system is released and the user base grows, the demands on the development and support team will increase.

The development team can scale vertically by adding new people to the team.

6 0
2 years ago
Other questions:
  • When are numbered lists generally used?
    14·2 answers
  • I need an answer fast !!! (APEX)
    13·1 answer
  • To execute a prepared SQL statement, you can use the _______ and execute methods of the PDOStatement object to set parameter val
    9·1 answer
  • How to build an arch bridge​
    5·1 answer
  • 1.Electromagnetic waves can carry more data at higher frequencies. Why would a scientist opt to transmit data at a lower frequen
    12·1 answer
  • Consider the following classes: public class Vehicle {...} public class Car extends Vehicle {...} public class SUV extends Car {
    8·1 answer
  • Which approach to knowledge management capitalizes on tacit knowledge and requires heavy IT investment?
    7·1 answer
  • Draw AND, OR, XOR and XNOR gates with truth table and logic gates.<br><br>.​
    11·1 answer
  • Final one bit l y links are a virus that will corrupt your files do not go on it
    15·2 answers
  • Fill in the blank
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!