{-# Language QuasiQuotes #-}
module Main where
import Data.Ix (inRange)
import Advent (format, countBy)
main :: IO ()
IO ()
main =
do [(Int, Int, Int, Int)]
input <- [format|2022 4 (%u-%u,%u-%u%n)*|]
Int -> IO ()
forall a. Show a => a -> IO ()
print (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ ((Int, Int, Int, Int) -> Bool) -> [(Int, Int, Int, Int)] -> Int
forall (f :: * -> *) a. Foldable f => (a -> Bool) -> f a -> Int
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) [(Int, Int, Int, Int)]
input
Int -> IO ()
forall a. Show a => a -> IO ()
print (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ ((Int, Int, Int, Int) -> Bool) -> [(Int, Int, Int, Int)] -> Int
forall (f :: * -> *) a. Foldable f => (a -> Bool) -> f a -> Int
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) [(Int, Int, Int, Int)]
input