fork download
  1. import Data.List
  2. import Data.Function
  3.  
  4. main = getContents >>= \vvod -> let
  5. bitiki = filter (all (`elem` "01")) $ words vvod
  6. baytiki = sobratBaytiki bitiki
  7. in mapM_ (putStrLn . intercalate " + ") baytiki
  8.  
  9. skleitBaytik bitiki = f 0 [] bitiki where
  10. f n baytik w@(~((c@(~(b:bs))):bitiki))
  11. | n==8 = [(baytik,w)]
  12. | 8<n || null w = []
  13. | null c = f n baytik bitiki
  14. | otherwise = take 1 (da ++ ne) where
  15. da = f (n+length b) (b:baytik) (bs:bitiki)
  16. ne = map (fmap (c:)) (f n baytik bitiki)
  17.  
  18. sobratBaytiki bitiki =
  19. map fst $ concat $ takeWhile (/=[]) $
  20. iterate (skleitBaytik . snd . head)
  21. [([],podgotovit bitiki)]
  22.  
  23. podgotovit = groupBy ((==) `on` length) . sortBy (flip compare `on` length)
Success #stdin #stdout 0.01s 5272KB
stdin
 11000011 10011011 00101111 00101101 00111011 10100000 11011011 110001
stdout
11000011
10011011
00101111
00101101
00111011
10100000
11011011