Skip to content

Instantly share code, notes, and snippets.

@kkirsanov
Created November 7, 2012 13:38
Show Gist options
  • Select an option

  • Save kkirsanov/4031622 to your computer and use it in GitHub Desktop.

Select an option

Save kkirsanov/4031622 to your computer and use it in GitHub Desktop.
import Data.List
import Data.Digest.CRC32 (crc32)
import Codec.Binary.UTF8.String(encode)
split :: String->String->[String]
split [] _ = []
split st ch = start : split ending ch where
checkChars :: String->Char->Bool
checkChars [] _ = False
checkChars (x:xs) char = (x==char) || checkChars xs char
(start, e) = break (checkChars ch) st
ending = drop 1 e
splitPar::String->[String]
splitPar st = split (removeDoubleN st) "\n"
splitSent::String->[String]
splitSent st = split st "!.?"
sortSent::[String]->[String]
sortSent = sortBy sls where
sls :: String->String->Ordering
sls a b | length a < length b = GT
| length a > length b = LT
| otherwise = compare a b
removeDoubleN::String->String
removeDoubleN (x:y:xs) | (x==y) && (y=='\n') = removeDoubleN (x:xs)
| otherwise = x:removeDoubleN (y:xs)
removeDoubleN x = x
textHash txt = map (crc32 . encode . concat. take 2 . sortSent . splitSent) (splitPar txt)
main = do
f <- readFile "1.txt"
let z = textHash f
mapM_ print z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment