From 64dedab06aea485042622fb502bba20be914ece0 Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Sun, 2 Dec 2018 18:44:24 +0530 Subject: [PATCH] Adds solution 2 --- 2/2.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 2/2.hs diff --git a/2/2.hs b/2/2.hs new file mode 100644 index 0000000..aa16fe7 --- /dev/null +++ b/2/2.hs @@ -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 \ No newline at end of file