What are the types of these functions?
triple x = 3 * x
even x = (x `mod` 2 == 0)
palindrome xs = (reverse xs == xs)
zip [] [] = []
zip (x : xs) (y : ys) = (x, y) :
(zip xs ys)
f x = f x
Which of these functions is equivalent to the built-in operator
||
?
or _ True = True
or True _ = True
or _ _ =
False
or True False = True
or True True = True
or
False True = True
or False False = False
or a b = b || a
Write a function primeFactors
that takes an integer
and returns a list of its prime factors in ascending order:
> primeFactors 60 [2, 2, 3, 5]
Write a function that takes an integer N and returns a list of all integer triples (a, b, c) with 0 < a < b < c ≤ N such that a2 + b2 = c2:
> triples 15
[(3,4,5),(6,8,10),(5,12,13),(9,12,15)]
Your function should run in time O(N3).
Make your function more efficient so that it runs in O(N2 log N). Do not use any floating-point numbers.
Write a function that adds two matrices represented as lists of lists.
Write a function that transposes a matrix represtented as a list of lists.
Write a function that sorts a list using an insertion sort.
Write a function that sorts a list using a merge sort.
Construct an infinite list allPairs
that contains all
pairs of positive integers. Every pair must appear exactly once in
the list.
Write a function that returns a list of all permutations of a given list.