-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay25.hs
30 lines (26 loc) · 961 Bytes
/
Day25.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
import qualified Data.Attoparsec.Text as At
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import Control.Monad
import Control.Applicative
import Data.List
import Debug.Trace
import Commons
import Algorithms
data Item = Lock [Int] | Key [Int] deriving (Show, Eq, Ord)
parser :: At.Parser (S.Set Item)
parser = do
let c = At.satisfy $ At.inClass "#."
r = At.count 5 c
rs = do
i <- At.count 7 (r <* At.endOfLine)
let kind = if head (head i) == '#' then Lock else Key
return $ kind $ map (pred . length . filter (== '#')) $ transpose i
S.fromList <$> At.sepBy1 rs At.endOfLine
main :: IO ()
main = do
items <- inp parser
let locks = S.filter (\case (Lock _) -> True; _ -> False) items
keys = S.filter (\case (Key _) -> True; _ -> False) items
print $ sum [1 | (Lock l) <- S.toList locks, (Key k) <- S.toList keys, all (<= 5) $ zipWith (+) l k]
return ()