Powerlist Powerplay

These exercises are going to see how you fair with basic recursive functions over lists.

  1. Write a function that finds the length of a list

  2. Write a function that sums up a list of numbers

  3. Write a function that adds 4 to every element of [2, 3, 4, 5]

  4. Write a function that finds the average of a list of numbers (Hint: this function isn’t in itself recursive, but uses ones that are)

  5. Write a function that returns every 2nd element in a list

  6. Write a function which finds the length of each list in a list of lists i.e. f [[1,2,3,4],[5,6],[7]] = [4,2,1]

  7. Write a function that splits a list into the first three elements and the rest i.e. f [1,2,3,4,5,6,7,8,9] = ([1,2,3],[4,5,6,7,8,9])

  8. Write a function that splits a list in blocks of 3. i.e. f [1,2,3,4,5,6,7,8,9] = [[1,2,3],[4,5,6],[7,8,9]]

  9. Write a function which checks if a list of booleans are all false.

  10. Write a function which checks if a list of a list of booleans are all false.

  11. Write a function which checks if a list contains duplicates

  12. Write a function that gets the element at the i’th index

  13. Write a function that returns the last element of a list

  14. Write a function that returns an infinite list of type a

  15. Write a function that returns n many elements from the end of a list (Hint: use the length function)

  16. Write a funciton that returns the 2nd last element of a list

  17. Write a function that returns a reversed list

  18. Write a funciton that determines whether a list is a palindrome

  19. Eliminate consecutive duplicates of list elements. If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.