Webpage of the Compositional Systems and Methods group at TalTech.
Email the folowing files to pawel@cs.ioc.ee:
Deadline 12:00 19/02/2020
differences [] == []
differences [5] == []
differences [5, 7, 12, 20] == [2, 5, 8]
titlecase "hello" == "Hello"
titlecase "it was the best of times" == "It Was The Best Of Times"
Hints: recall pack and unpack from last week, and read the
documentation for words and unwords. The function toUpper
will also be useful.
*idris> :exec interactive_titlecase
string> it was the best of times
It Was The Best Of Times
^D
avg_vowels "a e i o u"
1.0
avg_vowels "it was the best of times"
1.1666666666666667
avg_vowels "aAa EeE iIi xXx"
2.25
Hints:
is_vowel : Char -> Bool, using elem,average : List Nat -> Double, using cast and arithmetic.map unpack . words to get a list of lists of characters to analyze.satInBoth : (Eq t) => (t -> Bool) -> List t -> List t -> List t.
sat_in_both (< 5) [2,4,6,5] [3,4,6] == [4]
sat_in_both (==0) [1..10] [0..1] == []
satInBoth ((==5) . length) ["hello","world"] ["hello","bye"] == ["hello"]
Hint: use Data.List.intersect by importing Data.List.
ack : Nat -> Nat -> Nat.
ack 1 1 == 3
ack 1 2 == 4
ack 3 2 == 29
ack 4 0 == 13
least_greatest 5 [2,3,8,4,7] == (2,8)
least_greatest 0 [6..1] == (0,6)
Hints: Write a local function with the following signature:
min_max' : List Integer -> (Integer , Integer) -> (Integer ,
Integer) where the second argument is an accumulator consisting
of the least and greatest numbers seen so far in the list. Note
that you can pattern match on both the list and the pair. Use the
min and max functions from the standard library
sumevens 0 == 0
sumevens 1 == 0
sumevens 2 == 2
sumevens 3 == 6
sumevens 4 == 12
sum_primes 5 == 10
sum_primes 10 == 17
sum_primes 100 == 1060
sum_primes 1000 == 76127