Skip to content

Instantly share code, notes, and snippets.

@shhyou
Created May 4, 2018 04:07
Embed
What would you like to do?
import Data.List
import Data.Bool
histogramListComp ns = intercalate "\n" [[bool ' ' '*' (x `elem` ys) | x <- [0..9]] | ys <- reverse (transpose (group (sort ns)))] ++ "\n==========\n0123456789\n"
histogramCrypticRowMajor = (++ "\n==========\n0123456789\n") . intercalate "\n" . map (zipWith ($) (map ((bool ' ' '*' .) . elem) [0..9]) . repeat) . reverse . transpose . group . sort
histogramCrypticColMajorBuggy = (++ "\n==========\n0123456789\n") . intercalate "\n" . filter ('*' `elem`) . reverse . transpose . map ((++ replicate 1000 ' ') . (`replicate` '*')) . zipWith ($) (map ((length .) . filter . (==)) [0..9]) . repeat
_ = histogramListComp [1,4,5,4,6,6,3,4,2,4,9]
_ = histogramCrypticRowMajor [1,4,5,4,6,6,3,4,2,4,9]
_ = histogramCrypticColMajorBuggy [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