Skip to content

Instantly share code, notes, and snippets.

@arknave
Created December 25, 2016 03:55
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 arknave/f66e834f98da2d96fd6e09f83e028539 to your computer and use it in GitHub Desktop.
Save arknave/f66e834f98da2d96fd6e09f83e028539 to your computer and use it in GitHub Desktop.
Counts characters in Golf.hs. Strips out imports, type definitions, and whitespace
import Data.List.Split
valid :: String -> Bool
valid "" = False
valid s = not $ foldr (\a b -> b || a `elem` ["::", "import", "->", "module" ]) False $ words s
count :: String -> Int
count s = if valid s then length . concat $ words s else 0
main = do
file <- readFile "Golf.hs"
let validLines = filter (valid) . lines $ file
print validLines
let lineLengths = map count validLines
print lineLengths
print (sum lineLengths)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment