Haskell Functions examples

Status
Not open for further replies.

kellerkelly

Prominent
Jun 22, 2017
4
0
510
Hi i have been given the following question can someone help mean i have no idea what i'am doing.

Question 1


Write a function that checks if a given number is a "perfect number" using a list comprehension. A number x is considered perfect if all of its factors add up to x, e.g. 6 is perfect because 1 + 2 + 3 = 6. The output should be a Bool. Include the type signature of the function.

Question 2


Write a function that merges two ordered lists of numbers into one using recursion and pattern matching. Include the type signature of the function.

Question 3


Write a function that checks if two given student P-numbers (e.g. "P09876543" and "P17234567") are from the same year (i.e. they both start with the same two digits after the initial P). The output should be of type Bool. Include the type signature of the function.

Question 4

Write a function that calculates your tax band based on a given yearly income using a guarded equation. Your output should be a string. Include the type signature of the function. You can check the UK's tax rates on the government website https://www.gov.uk/income-tax-rates.

Question 5

Write a function, group n xs, that groups a string, xs, into a list of substrings of a size n. If necessary, the last string may contain fewer than n characters. Thus, group 5 "abcdefghijklm" = ["abcde", "fghij", "klm"]

 
Status
Not open for further replies.