Created
July 23, 2016 06:35
-
-
Save rhaseven7h/9279ea1c4dfecffc85bb3a4ef984dc85 to your computer and use it in GitHub Desktop.
HackerRank.com - Functional Programming - Prefix Compression - Haskell
This file contains hidden or 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
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 | |
This file contains hidden or 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
abcdefpr | |
abcpqr |
This file contains hidden or 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
3 abc | |
5 defpr | |
3 pqr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment