{-# Language QuasiQuotes, ParallelListComp #-}
module Main where
import Advent (countBy, format)
main :: IO ()
IO ()
main =
do [Int]
input <- [format|2021 1 (%u%n)*|]
Int -> IO ()
forall a. Show a => a -> IO ()
print (Int -> [Int] -> Int
solve Int
1 [Int]
input)
Int -> IO ()
forall a. Show a => a -> IO ()
print (Int -> [Int] -> Int
solve Int
3 [Int]
input)
solve ::
Int ->
[Int] ->
Int
solve :: Int -> [Int] -> Int
solve Int
n [Int]
input = (Bool -> Bool) -> [Bool] -> Int
forall (f :: * -> *) a. Foldable f => (a -> Bool) -> f a -> Int
countBy Bool -> Bool
forall a. a -> a
id [Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
y | Int
x <- [Int]
input | Int
y <- Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
drop Int
n [Int]
input]