]> git.rkrishnan.org Git - yorgey.git/blob - hw3/Golf.hs
057d2849eda29d2cfd61b3cd2127d858bf64c72e
[yorgey.git] / hw3 / Golf.hs
1 module Golf where
2
3 -- exercise 1
4 skips :: [a] -> [[a]]
5 skips xs = [map snd $ filter (\(i, _) -> (i `mod` n) == 0) $ zip [1..] xs | n <- [1 .. length xs]]
6
7 localMaxima :: [Integer] -> [Integer]
8 -- localMaxima xs = [p <- zip [0..length xs] xs], n <- [1 .. (length xs - 1)], fst p
9 localMaxima [] = []
10 localMaxima [_] = []
11 localMaxima [_,_] = []
12 localMaxima [x,y,z] | y > x && y > z = [y]
13                     | otherwise = []
14 localMaxima (x:y:z:xs) = localMaxima [x,y,z] ++ localMaxima (y:z:xs)
15
16 localMaxima' :: [Integer] -> [Integer]
17 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]
18