3 import qualified Data.Map as M
4 import qualified Data.List as L
8 skips xs = [map snd $ filter (\(i, _) -> (i `mod` n) == 0) $ zip [1..] xs | n <- [1 .. length xs]]
10 localMaxima :: [Integer] -> [Integer]
11 -- localMaxima xs = [p <- zip [0..length xs] xs], n <- [1 .. (length xs - 1)], fst p
14 localMaxima [_,_] = []
15 localMaxima [x,y,z] | y > x && y > z = [y]
17 localMaxima (x:y:z:xs) = localMaxima [x,y,z] ++ localMaxima (y:z:xs)
19 localMaxima' :: [Integer] -> [Integer]
20 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]
22 frequency :: [Integer] -> [(Integer, Integer)]
23 frequency xs = M.toList $ M.fromListWith (+) ([(c,1) | c <- xs] ++
24 [(c,0) | c <- [0..9]])
25 numStars :: Integer -> String
26 numStars n = take (fromInteger n) (repeat '*')
28 numSpaces :: Integer -> String
29 numSpaces n = take (fromInteger n) (repeat ' ')
31 histogram' xs = let freqs = [b | (_,b) <- frequency xs]
34 reverse $ L.transpose $ [take (fromInteger m) (numStars b ++ numSpaces (10 - b)) | b <- freqs]
36 histogram :: [Integer] -> String
37 histogram xs = (L.concat $ L.intersperse "\n" $ histogram' xs) ++ "\n"
38 ++ replicate 10 '=' ++ "\n" ++ (L.concat $ map show [0..9]) ++ "\n"