nb: must be done in haskell. your solution must include comments detailing how your code works. each function must be an
Posted: Fri Jul 01, 2022 5:33 am
nb: must be done in haskell. your solution must include comments detailing how your code works. each function must be annotated by comments precisely detailing how it works. 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 wayQuestion: NB: Must Be Done In Haskell. Your Solution Must Include Comments Detailing How Your Code Works. Each Function Must Be Annotated By Comments Precisely Detailing How It Works. 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 WayThis problem has been solved!See the answerNB: Must be done in Haskell. Your solution must include comments detailing how your code works. Each function must be annotated by comments precisely detailing how it works.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 USI numbers that does not involve searching the massive database of numbers. The validation method should distinguish valid USI numbers from random digits or typing mistakes. The implementation language is Haskell and the derived algorithm to do so is as follows:1. Every second digit beginning from the right is doubled. The last digit in the sequence therefore remains unchanged.For example, [1; 4; 3; 9; 1; 1; 5] becomes [1; 8; 3; 18; 1; 2; 5].2. Sum all single and double digits from the list.For example, [1 + 8 + 3 + 18 + 1 + 2 + 5] becomes 1 + 8 + 3 + 1 + 8 + 1 + 2 + 5 = 29.3. Calculate the remainder of the sum divided by 10. Using the result of the example above, the remainder is 9. If the remainder is equal to 0 then the number is valid, otherwise it is invalid.To aid with your solution design and marks allocation, it is recommended that you complete this assignment as a series of exercises.Exercise 1 Converting To DigitsThe 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 followingfunctions 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 DigitsNext, 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 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] -> IntegerExample: totalDigits [1; 4; 3; 8; 5; 12; 7] = 1 + 4 + 3 + 8 + 5 + 1 + 2 + 7 = 31Exercise 4 Verifying USIThe 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 -> BoolExample: verify 1834522 = TrueExample: verify 7896542 = False
nb: must be done in haskell. your solution must include comments detailing how your code works. each function must be annotated by comments precisely detailing how it works. 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
Question: NB: Must Be Done In Haskell. Your Solution Must Include Comments Detailing How Your Code Works. Each Function Must Be Annotated By Comments Precisely Detailing How It Works. 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
This problem has been solved!
See the answer
NB: Must be done in Haskell. Your solution must include comments detailing how your code works. Each function must be annotated by comments precisely detailing how it works.
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 USI numbers that does not involve searching the massive database of numbers. The validation method should distinguish valid USI numbers from random digits or typing mistakes. The implementation language is Haskell and the derived algorithm to do so is as follows:
1. Every second digit beginning from the right is doubled. The last digit in the sequence therefore remains unchanged.
For example, [1; 4; 3; 9; 1; 1; 5] becomes [1; 8; 3; 18; 1; 2; 5].
2. Sum all single and double digits from the list.
For example, [1 + 8 + 3 + 18 + 1 + 2 + 5] becomes 1 + 8 + 3 + 1 + 8 + 1 + 2 + 5 = 29.
3. Calculate the remainder of the sum divided by 10. Using the result of the example above, the remainder is 9. If the remainder is equal to 0 then the number is valid, otherwise it is invalid.
To aid with your solution design and marks allocation, it is recommended that you complete this assignment as a series of exercises.
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
functions 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 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
Exercise 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
nb: must be done in haskell. your solution must include comments detailing how your code works. each function must be annotated by comments precisely detailing how it works. 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
Question: NB: Must Be Done In Haskell. Your Solution Must Include Comments Detailing How Your Code Works. Each Function Must Be Annotated By Comments Precisely Detailing How It Works. 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
This problem has been solved!
See the answer
NB: Must be done in Haskell. Your solution must include comments detailing how your code works. Each function must be annotated by comments precisely detailing how it works.
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 USI numbers that does not involve searching the massive database of numbers. The validation method should distinguish valid USI numbers from random digits or typing mistakes. The implementation language is Haskell and the derived algorithm to do so is as follows:
1. Every second digit beginning from the right is doubled. The last digit in the sequence therefore remains unchanged.
For example, [1; 4; 3; 9; 1; 1; 5] becomes [1; 8; 3; 18; 1; 2; 5].
2. Sum all single and double digits from the list.
For example, [1 + 8 + 3 + 18 + 1 + 2 + 5] becomes 1 + 8 + 3 + 1 + 8 + 1 + 2 + 5 = 29.
3. Calculate the remainder of the sum divided by 10. Using the result of the example above, the remainder is 9. If the remainder is equal to 0 then the number is valid, otherwise it is invalid.
To aid with your solution design and marks allocation, it is recommended that you complete this assignment as a series of exercises.
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
functions 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 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
Exercise 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