### faster Solution for 5

Abhinav Sarkar 2 vuotta sitten
vanhempi
commit
780d339a68
1 muutettua tiedostoa jossa 7 lisäystä ja 7 poistoa
1. 7
7
5/5.hs

#### + 7 - 7 5/5.hsNäytä tiedosto

 ``@@ -25,20 +25,20 @@ simplify acc s`` 25 25 `` then simplify acc (S.drop 2 s)`` 26 26 `` else simplify (acc |> x) (S.drop 1 s)`` 27 27 `` `` 28 ``-collapse :: S.Seq Char -> Int`` 28 ``+collapse :: S.Seq Char -> S.Seq Char`` 29 29 `` collapse s =`` 30 30 `` let simplified = simplify S.empty s`` 31 31 `` in if S.length simplified == S.length s`` 32 ``- then S.length s`` 32 ``+ then s`` 33 33 `` else collapse simplified`` 34 34 `` `` 35 ``-betterCollapse :: S.Seq Char -> (Char, Int)`` 35 ``+betterCollapse :: S.Seq Char -> S.Seq Char`` 36 36 `` betterCollapse s =`` 37 ``- minimumBy (compare `on` snd)`` 38 ``- . map (\c -> (c, collapse \$ S.filter (\c' -> toLower c' /= toLower c) s))`` 37 ``+ minimumBy (compare `on` S.length)`` 38 ``+ . map (\c -> collapse \$ S.filter (\c' -> toLower c' /= toLower c) s)`` 39 39 `` \$ ['a' .. 'z']`` 40 40 `` `` 41 41 `` main = do`` 42 42 `` input <- S.fromList . filter (/= '\n') <\$> getContents`` 43 ``- putStrLn \$ "Size = " ++ show (collapse input)`` 44 ``- putStrLn \$ "Better Size = " ++ show (betterCollapse input)`` 43 ``+ putStrLn \$ "Size = " ++ show (S.length \$ collapse input)`` 44 ``+ putStrLn \$ "Better Size = " ++ show (S.length \$ betterCollapse (collapse input))``