Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
fp:exam2021:l2 [2021/06/02 18:36] pdmatei |
fp:exam2021:l2 [2021/06/03 15:43] (current) pdmatei |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Exam example 2 ====== | ====== Exam example 2 ====== | ||
- | 1. (2p) Write a function in Haskell which | + | 1. (2p) Write a function in Haskell which extracts all **even** positions from a list. Example ''f [1,2,3,4,5] = [1,3,5]'' |
- | 2. (2p) Write a function which removes those strings from a list, which are not in the date format. A correct date format is considered: ''DD.MM.YYYY'' where D,M,Y can be any digit. | + | 2. (2p) Write a function which takes a list of pairs ''Name-Age'' and returns the average age of names called ''Ana''. |
- | 3. (2p) Implement an Algebraic Datatype which encodes DNA bases: ('A', 'C', 'G', 'T'). Write a function which checks if two DNA sequences are **complementary**. 'A' is complementary to 'T' and 'C' to 'G'. For instance, ''AGTC'' is complementary to ''TCAG''. | + | 3. (2p) Implement an Algebraic datatype which encodes **semaphores**. A **semaphore** has a color (red, green, yellow). Write a function which checks if a list of semaphores is synchronised (all semaphores have the same color). |
- | 4. (1p) Write a function which takes an image (as encoded in the homework), a value k, and creates a ''k x k'' tiling of the image. | + | 4. (1p) Consider a 8x8 chessboard which contains only rooks, encoded as a matrix. The presence of a rook on a position is encoded by the character 'R'. The character ' ' encodes a free position. Write a function which takes a chessboard and returns true if two rooks attack each other. |
- | Example: | + | |
- | <code haskell> | + | |
- | .*. | + | |
- | img = **. | + | |
- | ... | + | |
- | .*..*..*. | + | |
- | **.**.**. | + | |
- | ......... | + | |
- | .*..*..*. | + | |
- | tile 3 img = **.**.**. | + | |
- | ......... | + | |
- | .*..*..*. | + | |
- | **.**.**. | + | |
- | ......... | + | |
- | </code> |