Skip to content

Instantly share code, notes, and snippets.

@rhaseven7h
Created July 23, 2016 06:35
Show Gist options
  • Save rhaseven7h/9279ea1c4dfecffc85bb3a4ef984dc85 to your computer and use it in GitHub Desktop.
Save rhaseven7h/9279ea1c4dfecffc85bb3a4ef984dc85 to your computer and use it in GitHub Desktop.
HackerRank.com - Functional Programming - Prefix Compression - Haskell
slv n "" _ = n
slv n _ "" = n
slv n a b
| fa == fb = slv (n + 1) (tail a) (tail b)
| otherwise = n
where fa = head a
fb = head b
main = do
raw <- readFile "input.txt"
let lns = lines raw
str1 = head lns
str2 = last lns
plen = slv 0 str1 str2
pfx = take plen str1
rstr1 = drop plen str1
rstr2 = drop plen str2
putStrLn $ (show plen) ++ " " ++ pfx
putStrLn $ (show $ length rstr1) ++ " " ++ rstr1
putStrLn $ (show $ length rstr2) ++ " " ++ rstr2
abcdefpr
abcpqr
3 abc
5 defpr
3 pqr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment