From 6116019fce50e1e14dd37c8dd7f627e058396d9c Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Wed, 17 Dec 2014 13:17:15 +0530 Subject: [PATCH] hw #3. WIP --- hw3/Golf.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 hw3/Golf.hs diff --git a/hw3/Golf.hs b/hw3/Golf.hs new file mode 100644 index 0000000..057d284 --- /dev/null +++ b/hw3/Golf.hs @@ -0,0 +1,18 @@ +module Golf where + +-- exercise 1 +skips :: [a] -> [[a]] +skips xs = [map snd $ filter (\(i, _) -> (i `mod` n) == 0) $ zip [1..] xs | n <- [1 .. length xs]] + +localMaxima :: [Integer] -> [Integer] +-- localMaxima xs = [p <- zip [0..length xs] xs], n <- [1 .. (length xs - 1)], fst p +localMaxima [] = [] +localMaxima [_] = [] +localMaxima [_,_] = [] +localMaxima [x,y,z] | y > x && y > z = [y] + | otherwise = [] +localMaxima (x:y:z:xs) = localMaxima [x,y,z] ++ localMaxima (y:z:xs) + +localMaxima' :: [Integer] -> [Integer] +localMaxima' xs = [b | [a,b,c] <- [drop (snd pair) (fst pair) | pair <- zip [[ p | p <- fst (splitAt n xs)] | n <- [3..length xs]] [0..]], b > a && b > c] + -- 2.37.2