fork download
  1. findRule = chk [] . rec
  2. where
  3. rec [] = []
  4. rec (x:xs) = case span (/=x) xs of (as,bs) -> (x:as) : rec bs
  5. chk _ [] = []
  6. chk key (x:xs)
  7. | and $ zipWith (==) xs $ cycle k = concat k
  8. | otherwise = chk k xs
  9. where
  10. k = key ++ [x]
  11.  
  12. main :: IO ()
  13. main = test
  14.  
  15. test = do
  16. let s ==> t = print $ findRule s == t
  17. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ==> "a"
  18. "123412312341231234123123412312341231234123" ==> "1234123"
  19. "oxoxoxoxoxoxoxoxxoxoxoxoxoxoxoxoxx" ==> "oxoxoxoxoxoxoxoxx"
  20. "axaxa" ==> "axaxa"
  21. "" ==> ""
  22.  
Success #stdin #stdout 0s 6264KB
stdin
Standard input is empty
stdout
True
True
True
True
True