Created
May 6, 2018 17:36
-
-
Save YuRen-tw/b4efa55f68cf04be76996eda6b2fdb1f to your computer and use it in GitHub Desktop.
FLOLAC 2018 0-2
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
import Data.List | |
histogram :: [Int] -> String | |
histogram = unlines . reverse . putNumber . transpose . mkLines | |
where putNumber = ("0123456789" :) . ("==========" :) | |
mkLines :: [Int] -> [String] | |
mkLines = graph . group . sort . ([0..9] ++) | |
graph :: [[Int]] -> [String] | |
graph = fst . (foldr graph' ([], 0)) | |
where graph' xs (ys, prevLen) = ((take len (mkStar xs)):ys, len) | |
where len = max prevLen (length xs) | |
mkStar :: [Int] -> String | |
mkStar = (++ repeat ' ') . tail . map (const '*') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment