-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.hs
71 lines (57 loc) · 2.23 KB
/
6.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{-# LANGUAGE GADTs #-}
import Data.Maybe
import Data.Kind
import Lib
dummyInput = unlines $ ["abc"
,""
,"a"
,"b"
,"c"
,""
,"ab"
,"ac"
,""
,"a"
,"a"
,"a"
,"a"
,""
,"b"]
{-
getAnswerCount :: [String] -> Int
getAnswerCount = length . distinct . foldr1 (++)
-}
allContain :: Eq a => [[a]] -> a -> Bool
allContain lists a = and $ map (a `elem`) lists
main = do
let allOfGroups = filter (/= "") . map (filter (/= '\n')) . (`splitOn` "\n\n")
distinctForGroups = map distinct . allOfGroups
distinctLengths = map length
dummyDistinct = distinctForGroups dummyInput
-- dummy --
putStrLn $ "ansers counts in dummyInput: " ++
(show $ distinctLengths $ dummyDistinct)
putStrLn $ "ansers sum in dummyInput: " ++
(show $ sum $ distinctLengths $ dummyDistinct)
-- input --
contents <- readFile "6.input"
let distincts = distinctForGroups contents
putStrLn $ "ansers sum in Input: " ++
(show $ sum $ distinctLengths $ distincts)
------------------ 2 ----------------------------------------
let parseInputs' = map (filter (/= "")) . map (`splitOn` "\n") . (`splitOn` "\n\n")
getAnswers inp = map (length . filter (==True))
$ map (\(d,i) -> map (i `allContain`) d)
$ zip (distinctForGroups inp) $ parseInputs' inp
dummyAnswers = getAnswers dummyInput
answers = getAnswers contents
-- dummy --
putStrLn $ "allContains in dummyInput: " ++
(show $ dummyAnswers)
putStrLn $ "sum allContains in dummyInput: " ++
(show $ sum dummyAnswers)
-- input --
--putStrLn $ "allContains in input: " ++
-- (show $ answers)
putStrLn $ "sum allContains in input: " ++
(show $ sum answers)