Skip to content

Instantly share code, notes, and snippets.

@YuRen-tw
Created May 6, 2018 17:36
Embed
What would you like to do?
FLOLAC 2018 0-2
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