{-# Language QuasiQuotes #-}
module Main where
import Data.Ix (inRange)
import Advent (format, countBy)
main :: IO ()
IO ()
main =
do input <- [format|2022 4 (%u-%u,%u-%u%n)*|]
print $ countBy (\(Int
a,Int
b,Int
c,Int
d) -> Int
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
c Bool -> Bool -> Bool
&& Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
b Bool -> Bool -> Bool
|| Int
c Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
a Bool -> Bool -> Bool
&& Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
d) input
print $ countBy (\(Int
a,Int
b,Int
c,Int
d) -> (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
a,Int
b) Int
c Bool -> Bool -> Bool
|| (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
a,Int
b) Int
d Bool -> Bool -> Bool
|| (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
c,Int
d) Int
a Bool -> Bool -> Bool
|| (Int, Int) -> Int -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (Int
c,Int
d) Int
b) input