You are viewing a single comment's thread. Return to all comments →
Haskell
module Main where import Control.Monad (replicateM_) import qualified Data.Map as M solve :: String -> Int solve s = if odd $ length s then (-1) else sum $ M.filter (> 0) $ M.differenceWith (\a b -> Just (a - b)) m1 m2 where zerocounts = M.fromList $ map (,0) s half = length s `div` 2 s1 = take half s m1 = foldl (\m c -> M.insertWith (+) c 1 m) zerocounts s1 s2 = drop half s m2 = foldl (\m c -> M.insertWith (+) c 1 m) zerocounts s2 main :: IO () main = readLn >>= flip replicateM_ (getLine >>= print . solve)
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
Haskell