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
igomit [66]
3 years ago
10

Define a function romanDigitToInt that converts a single Roman digit to a decimal integer. This function takes an argument as a

element of the RomanDigit union type and transforms it into the decimal integer using patter matching. This function should have signature: RomanDigit -> int.
Computers and Technology
1 answer:
raketka [301]3 years ago
3 0

Answer:

let convertRomanToInt romanNumber : int =

match romanNumber with

| 'I' -> 1

| 'V' -> 5

| 'X' -> 10

| 'L' -> 50

| 'C' -> 100

| 'D' -> 500

| 'M' -> 100

let rec romanNumberToInteger romanNumber =

if (String.length romanNumber = 1) then

convertRomanToInt romanNumber.[0]

elif (String.length romanNumber = 0) then  0

else  let atuple = (romanNumber.[0],romanNumber.[1])

let f atuple =  match atuple with

| (f,s) when (convertRomanToInt f) >=(convertRomanToInt s)->(convertRomanToInt f) + (romanNumberToInteger romanNumber.[1..])

| (f,s) when (convertRomanToInt f) < (convertRomanToInt s) -> (convertRomanToInt s) - (convertRomanToInt f) + (romanNumberToInteger romanNumber.[2..])

f atuple

let charToRomanDigit c =

printfn "%c" c

match c with

| 'I' -> 'I'

| 'V' -> 'V'

| 'X' -> 'X'

| 'L' -> 'L'

| 'C' -> 'C'

| 'D' -> 'D'

| 'M' -> 'M'

| _ -> failwith "Invalid Entry"

let stringToNumber str =

let upperDigit (x:string) = x.ToUpper()

let upperString = upperDigit str

printfn "%s" upperString

String.collect (fun c -> sprintf "%c" (charToRomanDigit c)) upperString

let romanNumber = "XIX"

let upperDigit (x:string) = x.ToUpper()

printfn "a: %s" (upperDigit romanNumber)

romanNumber = stringToNumber romanNumber

printfn "\nValue = %d" (romanNumberToInteger romanNumber)

Explanation:

  • Create a function called convertRomanToInt  for pattern matching to convert romanNumber to valid integer
  • Create a recursive function called romanNumberToInteger  and check if length of romanNumber is 1 or 0 .
  • Check whether the first character is less than second character, then its reverse  otherwise it's normal .
  • Create tuple of first and second character  for pattern matching .
  • Create a function charToRomanDigit  and use String.collect to go through each character present in string and reconstruct them again .
  • System.Char.ToUpper is used to convert a character to uppercase and stringToNumber to convert string in valid Roman number .
  • Finally print the results.
You might be interested in
A professional bureaucracy is a knowledge-based organization where goods and services depend on the expertise and knowledge of p
PtichkaEL [24]

Answer:

True

Explanation:

<em>Professional bureaucracy</em> is considered as a combination of professionals withing a government or private organization, these professionals are relied on to achieve productivity and are involved in making major decisions or implementing major regulations that decide the future of the organization.

In other words, professional bureaucracy grants employed professionals flexibility in carrying out their responsibilities in the organization, i.e., greater control of their duties.

6 0
3 years ago
A palindrome is a word or phrase that reads the same both backward and forward. The word ""racecar"" is an example. Create an al
oee [108]

Answer:

Algorithm for the above problem:

  1. Take a string from the user input.
  2. store the input string on any variable.
  3. Reverse the string and store it on the other variable.
  4. Compare both strings (character by character) using any loop.
  5. If all the character of the string matched then print that the "Input string is a palindrome".
  6. Otherwise, print "The inputted string is not a palindrome."

Output:

  • If the user inputs "ababa", then it prints that the "Input string is palindrome"
  • If the user inputs "ababaff", then it prints that the "Input string is not palindrome"

Explanation:

  • The above-defined line is a set of an algorithm to check the number is palindrome or not.
  • It is defined in English because the algorithm is a finite set of instructions written in any language used to solve the problem.
  • The above algorithm takes input from the user, compare that string with its reverse and print palindrome, if the match is found.
4 0
3 years ago
One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input
WINSTONCH [101]

Answer:

F(x) = x*.25

Explanation:

the amount of miles (x) divided by 4 (four quarters in a mile) or just multiply by .25

6 0
3 years ago
Read 2 more answers
Which of these is a neologism created as a result of the information age?
katrin [286]

The neologism created as a result of the information age is  Bromance (meaning "a male friendship").

<h3>What is  Neologism?</h3>

A neologism, is known to be a word, or phrase that tells or implies the process of an isolated thing entering common use, but have not been fully taken in by all.

Note that The neologism created as a result of the information age is  Bromance (meaning "a male friendship").

Learn more about neologism  from

brainly.com/question/9724482

#SPJ1

3 0
2 years ago
Hey how are yall today?
Luda [366]

Answer:

Great how are you today?

5 0
3 years ago
Read 2 more answers
Other questions:
  • Write a function called printEvens that prints all the even numbers between 2 and 20, inclusive. It will take no arguments and r
    6·1 answer
  • Using symbols (%, $, #, etc.) can make it easier to take notes.
    8·2 answers
  • Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2, the
    7·1 answer
  • You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?
    5·1 answer
  • Assume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declar
    12·1 answer
  • What is the main component of the EV3 Lego Robot called?​
    6·1 answer
  • You are planning a program to find the maximum heart rate recommended for patrons of a gym where you have a part-time job. One f
    13·1 answer
  • "Rights and duties are two sides of the same coin." Explain with examples​
    5·1 answer
  • What is the purpose of heading tags?
    15·1 answer
  • When trying to upload assignment on canvas wont let me click choose file.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!