Haskell CW II.B1

Review assignment.

  1. (p1) Write a function p1 that returns true if a number is a multiple of 17. Also write a signature for p1.

  2. The following function’s purpose is to return the elements of xs that are odd multiples of 7. What is wrong with the function as written? Also write an improved version.

     p2 xs = [ x | x <- xs, x `elem` [1,3..] && x `elem` [7,14..]]
    
  3. The function p3 takes in a list of words and returns a list with all of the words that have more than 4 letters. Also include words that alphabetically come after “x”. Write the signature and the function.

     p3 ["apple","yak","gut","a","cardio"] == ["apple","yak","cardio"]
    
  4. In p4 you produce a list of all of the numbers that are perfect cubes and not multiples of 3 between the lower and upper bounds (inclusive).

     p4 64 500 == [64,125,343]
    
  5. A Pythagorean triple (a,b,c) has c*c=a*a+b*b. Produce a list p5 of all Pythagorean triples (a,b,c) with a<80 and c<10000. It is OK to include triples where b<a.

  6. (p6) Given a list of Pythagorean triples, write a function to remove the ones with b<a.

  7. (p7) Given a list of Pythagorean triples, find the sum of all the hypotenuses. Test it using p5.

  8. Write a function p8 to find the product of all of the numbers in a list that are not divisors of 120. Start with a type signature.

    p8 [2,5,9,2,13,19,15] == 2223
    
  9. Write a recursive function p9 that works its way through a list, doubling each number, until it gets to the first 5 - where it stops (without including the 5). Start with a type signature.

    p9 [1,10,100] == [2,20,200]
    p9 [5] == []
    p9 [1,10,5,20,30] == [2,20]
    
  10. Write a recursive function pa that ignores each number in a list up to the first appearance of 13. It then outputs a list containing 10 times each of the numbers in the rest of the list.

    pa [1,2,3] == []
    pa [13,15] == [150]
    pa [1,2,3,13,15,16,17] == [150,160,170]
    pa [4,5,13] == []
    
  11. (Bonus) The auton function takes in two lists, a list of numbers to “avoid” and a list of numbers to process. Find the sum of all of the numbers in the list to process that are not in the “avoid” list. Start with a signature.

    auton avoid process = undefined  -- You write it
    
Last modified September 1, 2023: Edit: fix pythagorean triple typo. (919990f)