Created
May 3, 2018 16:26
-
-
Save jc99kuo/652f5ac2a8118ae1717a66e4cbea93cb to your computer and use it in GitHub Desktop.
FLOLAC 2018 Week 1 (2018-5-03 16:20) -- Histogram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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