Exercise set 3.
In this course week, we will be introducing a mini project that you will be working on for the next 3 weeks. And as such the exercises will be coursory and intended to prepare you for the task.
You should all read chapter 5 of Programming in Haskell by Graham Hutton, which explains list comprehensions (we will implement list comprehensions as part of the first Oblig).
Students who are struggeling with recursive functions are encouraged to also read chapter 6.
Highly engaged students are encouraged to read the Hutton and Wright's "calculating an exceptional machine" cited at the end of page 108.
In this exercise set, you will find exercises that you can use to test yourself, that you have understood the material covered in the course up to now.
Programming in Haskell
Solve the following exercises from Programming in Haskell by Graham Hutton.
- exercise 5.7.1
- exercise 5.7.4
- exercise 5.7.9
- exercise 6.8.6
- exercise 7.9.2
- exercise 7.9.3
- exercise 7.9.5
- exercise 8.9.5
- exercise 8.9.6
Morse Comprehensions
Recall the exercise about morse code from week 01, and find the alphabet listed below here for convenience.
A .- N -.
B -... O ---
C -.-. P .--.
D -.. Q --.-
E . R .-.
F ..-. S ...
G --. T -
H .... U ..-
I .. V ...-
J .--- W .--
K -.- X -..-
L .-.. Y -.--
M -- Z --..
-
Declare a function
encode :: String -> String
that takes a list of characters[Char]
and produces an encoded string usingconcat
and a list comprehension. -
Declare a function
decode :: String -> [String]
that takes a string encoded in morse code as argument and computes by list comprehension, all the possible translations.
List Comprehensions (challenge)
-
warmup using a list comprehension and
sum
solve problem 1 at project euler. -
define the sequence of Fibonacci numbers as an infinite list, use a list comprehension to solve problem 2 at project euler.
-
define the sequence of prime numbers as an infinite list, use a list comprehension to solve problem 3 at project euler.