Adds solution 2

master
Abhinav Sarkar 2018-12-02 18:44:24 +05:30
parent 9d534067ab
commit 8539d55995
1 changed files with 14 additions and 0 deletions

14
2/2.hs Normal file
View File

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