Last active
March 6, 2022 10:16
-
-
Save thyeem/06daf6bbc080d9c970e6b0870479b588 to your computer and use it in GitHub Desktop.
sng2c's problem
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
-- | Predicates strings of startWith | |
-- Just for clarify, the same of `isPrefixOf` | |
startWith :: (Eq a) => [a] -> [a] -> Bool | |
startWith [] _ = True | |
startWith _ [] = False | |
startWith (x : xs) (y : ys) = x == y && startWith xs ys | |
main :: String -> [(Int, String)] | |
main input = | |
[ (offset, sub) | |
| sub <- drop 1 . inits $ input | |
, offset <- [0 .. length input `div` 2 + 1] | |
, startWith sub (drop (offset + length sub) input) | |
] | |
-- tests | |
main "ABCABC" | |
main "A" | |
main "AA" | |
main "AAAA" | |
main "ABABABAB" | |
main "ABCABCAC" | |
main "AABAAC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/sng2c/6077247