Skip to content

Instantly share code, notes, and snippets.

@jc99kuo
Created May 3, 2018 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc99kuo/652f5ac2a8118ae1717a66e4cbea93cb to your computer and use it in GitHub Desktop.
Save jc99kuo/652f5ac2a8118ae1717a66e4cbea93cb to your computer and use it in GitHub Desktop.
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