From: Ramakrishnan Muthukrishnan Date: Wed, 17 Dec 2014 07:47:15 +0000 (+0530) Subject: hw #3. WIP X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/priv/frontends/FTP-and-SFTP.txt?a=commitdiff_plain;h=6116019fce50e1e14dd37c8dd7f627e058396d9c;p=yorgey.git hw #3. WIP --- 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] +