Implement some general functions on lists such that the following expressions evaluate to True
. Some of them can be found in the Prelude. Of course, do not use them.
myLast ['a', 'b', 'c', 'd'] == 'd'
myElementAt ['a', 'b', 'c', 'd'] 1 == 'b'
myElementAt ['a', 'b', 'c', 'd'] 2 == 'c'
Use a list as an accumulator to build up the list by prepending elements.
myRange 0 3 == [0, 1, 2, 3]
myRange 5 12 == [5, 6, 7, 8, 9, 10, 11, 12]
myDuplicate ['a', 'b', 'c'] == ['a', 'a', 'b', 'b', 'c', 'c']
myDuplicate [1, 2, 3] == [1, 1, 2, 2, 3, 3]
myMulticate ['a', 'b', 'c'] 2 == ['a', 'a', 'b', 'b', 'c', 'c']
myMulticate [1, 2, 3] 3 == [1, 1, 1, 2, 2, 2, 3, 3, 3]
myEven [5, 6, 7, 8, 9, 10, 11, 12] == [6, 8, 10, 12]
mySplitAt [5, 6, 7, 8, 9, 10, 11, 12] 3 = ([5, 6, 7], [8, 9, 10, 11, 12])
mySplitAt ['a', 'b', 'c', 'd'] 2 == (['a', 'b'], ['c', 'd'])
Consider the following list of numbers and write functions that answer a few questions about the numbers in that list. Do not use existing functions from the Prelude, except head
, tail
and (:)
.
z = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]
How many numbers are greater than five?
What is the smallest number greater than 5?
What is the average value of the numbers that come after a 5?