Browse Source

Adds solution 2

Abhinav Sarkar 2 years ago
parent
commit
8539d55995
1 changed files with 14 additions and 0 deletions
  1. 14
    0
      2/2.hs

+ 14
- 0
2/2.hs View File

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

Loading…
Cancel
Save