Created
May 7, 2018 18:03
-
-
Save Zekt/b6b28e8b60723239b4123ec98a4e4c6e to your computer and use it in GitHub Desktop.
practice for FLOLAC
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
toRecord :: (Int -> Int) -> Int -> (Int -> Int) | |
toRecord r x y | x == y = (r x) + 1 | |
| otherwise = r y | |
histogram :: [Int] -> String | |
histogram xs = unlines (f record max) ++ "==========\n0123456789\n" | |
where count = foldl toRecord (const 0) xs | |
record = map count [0..9] | |
max = maximum record | |
f :: [Int] -> Int -> [String] | |
f _ 0 = [] | |
f record most = map (\x -> if x < most then ' ' else '*') record : (f record (most-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment