Created
December 25, 2016 03:55
-
-
Save arknave/f66e834f98da2d96fd6e09f83e028539 to your computer and use it in GitHub Desktop.
Counts characters in Golf.hs. Strips out imports, type definitions, and whitespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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