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 5284KB
stdin
00110011 00111001 00110000 00110001 00110001 00110000 00110001 00110010 00110001 00110100 00110 010 010 01 00110100
stdout
00110011
00111001
00110000
00110001
00110001
00110000
00110001
00110010
00110001
00110100
00110100
010 + 00110