Skip to content

Instantly share code, notes, and snippets.

@Zekt
Created May 7, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zekt/b6b28e8b60723239b4123ec98a4e4c6e to your computer and use it in GitHub Desktop.
Save Zekt/b6b28e8b60723239b4123ec98a4e4c6e to your computer and use it in GitHub Desktop.
practice for FLOLAC
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