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
A commercial depicts a teenager on a skateboard vandalizing a brick wall. This is an example of:
Olenka [21]
Crime. Because vandalizing is a crime. And maybe in the commercial the narrator will say something like don't do crime or something.
6 0
3 years ago
Read 2 more answers
You are building a gaming computer and you want to install a dedicated graphics card that has a fast gpu and 1gb of memory onboa
irga5000 [103]
Usually a graphics card would be plugged in manually through a PCI-e express slot on the motherboard. But to give the card enough power (based on how powerful the card is) you would use a 6 pin or an 8 pin power connector.
<span />
5 0
3 years ago
Read 2 more answers
Remember for a moment a recent trip you have made to the grocery store to pick up a few items. What pieces of data did the Point
Umnica [9.8K]

Answer:

Data: Data are raw facts and figures that are collected together for analysis. In other words, Simple no processing is data.

Information: Information is the facts provided about something. In simple terms, processed data is information.

Knowledge: Knowledge is the processed facts that are understand for a conclusion.

1. An item's UPC number - data

Explanation: An item number is data because simple no processing is required.

2. Change back to customer - information

Explanation: Data about a customer is information.

3. General changes to demand in different seasons - knowledge

Explanation: Requires data (time and quantity purchased) to be processed/aggregated into information. The information is understood to provide a pattern of demad changes due to seasons.

4. Cost each - data

Explanation: Cost each is data because simple no processing is required.

5. Quantity purchased - data

Explanation: Cost each is data because simple no processing is required.

6. Non-taxable total - information

Explanation: -- requires that data (prices, amounts and whether the item is taxable) to be processed (price * amount for items that are non-taxable).

7. Extended cost [quantity times cost each] - information

Explanation: Extended cost requires processing two pieces of data quantity and cost

8. Amount tendered - data

Explanation: Amount tendered is data because simple no processing is required.

9. Sales of an item for the last week - information

Explanation: Sales of an item for the last week requires aggregating sales for a specific time frame together

10. Upcoming holidays and customer's special needs - knowledge

Explanation: Upcoming holidays and customer's special needs requires holiday data (dates) to be combined with information gathered about customer to understand customer's special needs

11. How paid [cash, charge card, debit card] - data

Explanation: Cost each is data because simple no processing is required.

12. Shopper loyalty card number - data

Explanation: Cost each is data because simple no processing is required.

13. Taxable total - information

Explanation: Taxable total requires that data (prices, amounts and whether the item is taxable) to be processed (price * amount for items that are taxable).

Explanation:

6 0
3 years ago
In Microsoft Windows, which of the following typically happens by default when a file is "double-clicked"
Elenna [48]
Depending on the type of file, it normally runs or opens.
4 0
3 years ago
Read 2 more answers
A strategy to solve a logic problem is to break it into steps. Using the drop-down menu, complete these sentences about solving
PSYCHO15rus [73]
I think the answer is 3!!
3 0
3 years ago
Read 2 more answers
Other questions:
  • Why is it more important now than ever before to know how to evaluate websites and other online sources of information?
    7·1 answer
  • Karen has opened a new business and is using Google Display Ads to build awareness of her new products. How does Google Display
    6·1 answer
  • Expressing your needs to others is aggressive behavior.<br> True or False?
    5·2 answers
  • Each tab is divided into groups of related commands or buttons. T or F
    10·1 answer
  • Write a function called show_info that takes a name, a home city, and a home state (a total of 3 arguments) and returns a full s
    12·1 answer
  • Durante 10s, la velocidad de rotación y el momento de giro de las ruedas de un coche eléctrico son 100 rpm y 1405,92 Nm, respect
    15·1 answer
  • PAGE<br>DATE<br>0 What types of information should be there internet?​
    5·1 answer
  • Define the instance method inc_num_kids() for PersonInfo. inc_num_kids increments the member data num_kids. Sample output for th
    6·1 answer
  • HELP ME?!!?!?!?!?!?
    9·2 answers
  • Describe a cellular network, its principle<br> components and how it works.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!