FLOLAC'18 prerequisite p2
This file contains 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
stat :: [Int] -> [Int] | |
stat [] = replicate 10 0 | |
stat (x:xs) = (take x stats) ++ [stats !! x + 1] ++ tail (drop x stats) | |
where stats = stat xs | |
plot :: [Int] -> [String] | |
plot ys | |
| all (== 0) ys = [] | |
| otherwise = row : plot ys' | |
where row = map (\y -> if y == 0 then ' ' else '*') ys | |
ys' = map (\y -> max 0 $ y - 1) ys | |
histogram :: [Int] -> String | |
histogram xs = unlines $ reverse $ "0123456789" : "==========" : plot (stat xs) | |
{- | |
ghci> putStr $ histogram [1,4,5,4,6,6,3,4,2,4,9] | |
* | |
* | |
* * | |
****** * | |
========== | |
0123456789 | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment