Skip to content

Instantly share code, notes, and snippets.

@syntacticsugar
Forked from trobertson/count-zero-golf.hs
Created November 20, 2012 21:28
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 syntacticsugar/4121282 to your computer and use it in GitHub Desktop.
Save syntacticsugar/4121282 to your computer and use it in GitHub Desktop.
countZeroes :: [String] -> Int
countZeroes = sum . map length . map (filter (=='0'))
countZeroesAgain :: Show a => [a] -> Int
countZeroesAgain = countZeroes . map show
-- and for the one line, because I guess that's the challenge
-- btw, it's type is
-- cz :: Show a => [a] -> Int
-- which means that this function works any list of things that can be printed
cz = sum . map length . map (filter (=='0')) . map show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment