Skip to content

Instantly share code, notes, and snippets.

@ivoscc
Created April 11, 2013 17:41
Show Gist options
  • Save ivoscc/5365488 to your computer and use it in GitHub Desktop.
Save ivoscc/5365488 to your computer and use it in GitHub Desktop.
Check if 2 strings are cycles
rotate :: [Char] -> [Char] -> Int -> Bool
rotate _ _ 0 = False
rotate s1 s2 len = if s1' == s2 then True else rotate s1' s2 (len-1)
where s1' = tail s1 ++ [head s1]
cyclep :: [Char] -> [Char] -> Bool
cyclep str1 str2 = rotate str1 str2 (length str1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment