Created
September 4, 2016 16:21
-
-
Save veer66/a35cbb4a521ea02cf992e27fb1a115b4 to your computer and use it in GitHub Desktop.
By using ByteString, this program becomes much faster than text/string version.
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 qualified Data.ByteString.Char8 as B | |
-- https://hackage.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString-Char8.html | |
splitBS x y = h : if B.null t then [] else splitBS x (B.drop (B.length x) t) where (h,t) = B.breakSubstring x y | |
countSplit row = length $ splitBS (B.pack " ||| ") row | |
readLines = B.getContents >>= (return . B.lines) | |
countToks lines = foldl (+) 0 (map countSplit lines) | |
main = readLines >>= (return . countToks) >>= (putStrLn . show) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment