Skip to content

Instantly share code, notes, and snippets.

@thyeem
Last active March 6, 2022 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thyeem/06daf6bbc080d9c970e6b0870479b588 to your computer and use it in GitHub Desktop.
Save thyeem/06daf6bbc080d9c970e6b0870479b588 to your computer and use it in GitHub Desktop.
sng2c's problem
-- | 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"
@thyeem
Copy link
Author

thyeem commented Mar 6, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment