Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FLOLAC 2018 Week 1 (2018-5-03 16:20) -- Histogram
-- FLOLAC 2018 Week 2 -- Histogram
histogram :: [Int] -> String
histogram ix =
concat [ row n | n <- [heigh, heigh - 1 .. 1]] ++
"==========\n" ++
"0123456789\n"
where
row m = [ if mm < m then ' ' else '*' | mm <- accl ] ++ "\n"
accl = [ length $ filter (== nn ) ix | nn <- [0 .. 9] ]
heigh = maximum accl
-- In GHCi we should put the histogram output in 'putSrtLn' function
-- In order to make "\n" actually be line feed
{- e.g.
putStrLn (histogram [])
putStrLn (histogram [1,2,3,4,5,6,7])
putStrLn (histogram [1,6,4,2,7,8,4,9,3,0,3,9,7,3])
putStrLn (histogram [1,4,5,4,6,6,3,4,2,4,9])
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment