From 27ae61a5ee94e413d2f9c1aefb1406454a3ac7d1 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Thu, 3 Jul 2025 21:22:51 +0200 Subject: add second exercise of lecture 3 --- lec03/Golf.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lec03/Golf.hs b/lec03/Golf.hs index b89aa57..e4fa9a3 100644 --- a/lec03/Golf.hs +++ b/lec03/Golf.hs @@ -22,3 +22,20 @@ skips l = map (\n -> concatMap (takeNth l . (*n)) nl) nl where len = length l nl = [1..len] + +-- Exercise 2 + +-- Explanation: +-- localMaxima is defined in two cases. In the first case, the argument of the +-- function is a list with at least 3 elments. Depending on the value of the +-- first three elements, checked through two guards, the second is either +-- included or excluded from the resulting list. In particular, the first guard +-- checks whether both the first and the third are smaller than the second using +-- the `all` function. The second case matches if the list has less than 3 +-- elements, in which case the result is just an empty list. +-- The list resulting from the `localMaxima` function is built recursively. +localMaxima :: [Integer] -> [Integer] +localMaxima (x1:x2:x3:xs) + | all (