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 software used to help run the computer hardware is the _____.
TiliK225 [7]
C. system software
if it means drivers and so on
6 0
3 years ago
Read 2 more answers
Write a program that prompts the user to input a number. The program should then output the number and a message saying whether
Gala2k [10]

Answer:

Following is the program in C++ Language

#include <iostream> // header file

using namespace std; // namespace std

int main() // main method

{

   int n;  // variable declaration

   cout<<" Please enter the number :";

   cin>>n; // Read the number

   if(n>0) // check the condition when number is positive

   {

cout<<n<<endl<<"The number is Positive"; // Display number

   }

  else if(n<0) // check the condition when number is Negative

  {

cout<<n<<endl<<"The number is Negative";// Display number

  }

  else // check the condition when number is Zero

  {

cout<<n<<endl<<"The number is Zero";// Display number

  }

   return 0;

  }

Output:

Please enter the number:

64

The number is Positive

Explanation:

Following are the description of the program

  • Declared a variable "n" of int type.
  • Read the value of "n" by user.
  • Check the condition of positive number by using if block statement .If n>0 it print the number is positive.
  • Check the condition of negative number by using else if block statement If n<0 it print the number is negative.
  • Finally if both the above condition is fail it print the message " The number is Zero"

7 0
3 years ago
Participants in open _________ community projects get experience and make connections with other professionals that can be valua
aleksandrvk [35]

Participants in open source community projects get experience and make connections with other professionals that can be valuable resources during a job hunt.

8 0
3 years ago
Who can help me please? ​
malfutka [58]

Answer:

what do you need help with

4 0
3 years ago
What products use fabric manipulation
Komok [63]
The fabric satin is good for fabric manipulation.
8 0
3 years ago
Other questions:
  • What control features will you use in the input screens to aid in data entry? give a specific example of how you will use at lea
    6·1 answer
  • Why should you log out when you finish an online session?
    9·1 answer
  • What sugar is used in a DNA molecule​
    7·2 answers
  • What is the rarest Supercar/hypercar you have ever seen?
    7·1 answer
  • WHAT SO THESE THINGS THAT I'VE HIGHLIGHTED MEAN IN MICROSOFT WORD?
    12·1 answer
  • Description:
    7·1 answer
  • Create an array of 10 fortune cookie sayings that will be randomly displayed each time the user reloads the page. The fortune wi
    5·1 answer
  • In learning information security, it is important to understand that threats to your company's information assets are present 24
    13·1 answer
  • If you wanted to include a chart in the new slide you are getting ready to create, you would most likely
    9·1 answer
  • The following method in Inventory is intended to count how many batteries are fully charged. What should replace /*Missing Code
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!