Complete the following exercises in Haskelllanguage. It must include comments detailing how the code works. Each functio
Posted: Fri Jul 08, 2022 7:27 am
Complete the following exercises in Haskelllanguage. It must include comments detailing how the code works. Each functionmust be annotated by comments preciselydetailing how it works.Exercise 1.Converting To DigitsThe USI is a 7 digit number. So, given a number of 7 digits, you will need to define afunction which converts these digits into a list ofindividual Integers. The followingStunctions can be defined:toDigits:: Integer -> (Integer]toDigitsReverse:: Integer -> [Integer].Both functions should convert a list of positiveIntegers to an Individual list of digitsWhere toDigitsReverse reverses the returned list.Example: toDigits 1234567 = [1,2,3,4,5,6, 7]Example: toDigitsReverse 1234567 = (7,6, 5, 4, 3,2, 1)Exercise 2.Doubling DigitsNext, the digits need to be doubled, for this thefollowing function can be defined:doubleDigits: (Integer] -> (Integer]The function doubleDigits must double every other number starting from the right.The second-to-last number is doubled first, thenthe fourth-to-last, and so on.Example: doubleDigits (1, 2, 3, 4, 5, 6, 7) = (1, 4, 3,8, 5, 12, 7)
Complete the following exercises in Haskell
language. It must include comments detailing how the code works. Each function
must be annotated by comments precisely
detailing how it works.
Exercise 1.
Converting To Digits
The USI is a 7 digit number. So, given a number of 7 digits, you will need to define a
function which converts these digits into a list of
individual Integers. The following
Stunctions can be defined:
toDigits:: Integer -> (Integer]
toDigitsReverse:: Integer -> [Integer].
Both functions should convert a list of positive
Integers to an Individual list of digits
Where toDigitsReverse reverses the returned list.
Example: toDigits 1234567 = [1,2,3,4,5,6, 7]
Example: toDigitsReverse 1234567 = (7,6, 5, 4, 3,2, 1)
Exercise 2.
Doubling Digits
Next, the digits need to be doubled, for this the
following function can be defined:
doubleDigits: (Integer] -> (Integer]
The function doubleDigits must double every other number starting from the right.
The second-to-last number is doubled first, then
the fourth-to-last, and so on.
Example: doubleDigits (1, 2, 3, 4, 5, 6, 7) = (1, 4, 3,8, 5, 12, 7)
Exercise 3.Totalling DigitsThe output of doubleDigits may be a combinationof one and two-digit numbers. A function such as the one which follows is neededto total all digits in the list producedby doubleDigits.totalDigits :: [Integer] -> IntegerExample: totalDigits [1, 4, 3,8,5,12,7] = 1 + 4+ 3+8+5+1+2+7 = 31Exercice 4Verifying USIThe final function will need to combine all functions created in the prior exercises andrespectively return True or False whether or not the provided USI is valid.verify :: Integer -> BoolExample: verify 1834522 = TrueExample: verify 7896542 = FalseThe University of Guyana is considering integrating online payments via the StudentsRecords Management System (SRMS). The idea is for students to provide their UniqueStudent Identification (USI) number upon payment so that the correct student accountis updated. There needs to be a quick way ofvalidating US numbers that does notinvolve searching the massive database ofnumbers. The validation method shoulddistinguish valid US numbers from random digitsor typing mistakes. The implementation language is Haskell and thederived algorithm to do so is as follows in the exercises above.
Exercise 3.
Totalling Digits
The output of doubleDigits may be a combination
of one and two-digit numbers. A function such as the one which follows is needed
to total all digits in the list produced
by doubleDigits.
totalDigits :: [Integer] -> Integer
Example: totalDigits [1, 4, 3,8,5,12,7] = 1 + 4+ 3+8+5+1+2+7 = 31
Exercice 4
Verifying USI
The final function will need to combine all functions created in the prior exercises and
respectively return True or False whether or not the provided USI is valid.
verify :: Integer -> Bool
Example: verify 1834522 = True
Example: verify 7896542 = False
The University of Guyana is considering integrating online payments via the Students
Records Management System (SRMS). The idea is for students to provide their Unique
Student Identification (USI) number upon payment so that the correct student account
is updated. There needs to be a quick way of
validating US numbers that does not
involve searching the massive database of
numbers. The validation method should
distinguish valid US numbers from random digits
or typing mistakes. The implementation language is Haskell and the
derived algorithm to do so is as follows in the exercises above.
Complete the following exercises in Haskell
language. It must include comments detailing how the code works. Each function
must be annotated by comments precisely
detailing how it works.
Exercise 1.
Converting To Digits
The USI is a 7 digit number. So, given a number of 7 digits, you will need to define a
function which converts these digits into a list of
individual Integers. The following
Stunctions can be defined:
toDigits:: Integer -> (Integer]
toDigitsReverse:: Integer -> [Integer].
Both functions should convert a list of positive
Integers to an Individual list of digits
Where toDigitsReverse reverses the returned list.
Example: toDigits 1234567 = [1,2,3,4,5,6, 7]
Example: toDigitsReverse 1234567 = (7,6, 5, 4, 3,2, 1)
Exercise 2.
Doubling Digits
Next, the digits need to be doubled, for this the
following function can be defined:
doubleDigits: (Integer] -> (Integer]
The function doubleDigits must double every other number starting from the right.
The second-to-last number is doubled first, then
the fourth-to-last, and so on.
Example: doubleDigits (1, 2, 3, 4, 5, 6, 7) = (1, 4, 3,8, 5, 12, 7)
Exercise 3.Totalling DigitsThe output of doubleDigits may be a combinationof one and two-digit numbers. A function such as the one which follows is neededto total all digits in the list producedby doubleDigits.totalDigits :: [Integer] -> IntegerExample: totalDigits [1, 4, 3,8,5,12,7] = 1 + 4+ 3+8+5+1+2+7 = 31Exercice 4Verifying USIThe final function will need to combine all functions created in the prior exercises andrespectively return True or False whether or not the provided USI is valid.verify :: Integer -> BoolExample: verify 1834522 = TrueExample: verify 7896542 = FalseThe University of Guyana is considering integrating online payments via the StudentsRecords Management System (SRMS). The idea is for students to provide their UniqueStudent Identification (USI) number upon payment so that the correct student accountis updated. There needs to be a quick way ofvalidating US numbers that does notinvolve searching the massive database ofnumbers. The validation method shoulddistinguish valid US numbers from random digitsor typing mistakes. The implementation language is Haskell and thederived algorithm to do so is as follows in the exercises above.
Exercise 3.
Totalling Digits
The output of doubleDigits may be a combination
of one and two-digit numbers. A function such as the one which follows is needed
to total all digits in the list produced
by doubleDigits.
totalDigits :: [Integer] -> Integer
Example: totalDigits [1, 4, 3,8,5,12,7] = 1 + 4+ 3+8+5+1+2+7 = 31
Exercice 4
Verifying USI
The final function will need to combine all functions created in the prior exercises and
respectively return True or False whether or not the provided USI is valid.
verify :: Integer -> Bool
Example: verify 1834522 = True
Example: verify 7896542 = False
The University of Guyana is considering integrating online payments via the Students
Records Management System (SRMS). The idea is for students to provide their Unique
Student Identification (USI) number upon payment so that the correct student account
is updated. There needs to be a quick way of
validating US numbers that does not
involve searching the massive database of
numbers. The validation method should
distinguish valid US numbers from random digits
or typing mistakes. The implementation language is Haskell and the
derived algorithm to do so is as follows in the exercises above.