Adds solution 2

Abhinav Sarkar 2018-12-02 18:44:24 +05:30
parent 9d534067ab
commit 64dedab06a
1 changed files with 13 additions and 0 deletions

13
2/2.hs Normal file
View File

@ -0,0 +1,13 @@
module Main where
import Data.List (group, sort)
main = do
ids <- lines <$> getContents
print (length (repeatCounts 2 ids) * length (repeatCounts 3 ids))
let (a, b) = head [(x, y) | x <- ids, y <- ids, countDiffChars x y == 1]
print $ filter (/= '!') $ zipWith (\x y -> if x == y then x else '!') a b
where
repeatCounts x = filter (x `elem`) . map (map length . group . sort)
countDiffChars as bs = sum $ zipWith (\a b -> if a == b then 0 else 1) as bs