2121-- solution. You can delete the type signatures completely and GHC
2222-- will recommend what should go in place of the underscores.
2323module AOC2025.Day05 (
24- -- day05a,
25- -- day05b
26-
24+ day05a ,
25+ day05b ,
2726)
2827where
2928
@@ -42,24 +41,29 @@ import qualified Data.OrdPSQ as PSQ
4241import qualified Data.Sequence as Seq
4342import qualified Data.Sequence.NonEmpty as NESeq
4443import qualified Data.Set as S
44+ import Data.ExtendedReal (Extended (.. ))
4545import qualified Data.Set.NonEmpty as NES
4646import qualified Data.Text as T
4747import qualified Data.Vector as V
4848import qualified Linear as L
4949import qualified Text.Megaparsec as P
5050import qualified Text.Megaparsec.Char as P
5151import qualified Text.Megaparsec.Char.Lexer as PP
52+ import qualified Data.Interval as I
53+ import qualified Data.IntervalSet as IVS
5254
5355day05a :: _ :~> _
5456day05a =
5557 MkSol
5658 { sParse =
57- noFail $
58- lines
59+ noFail \ xs -> case splitOn " \n\n " xs of
60+ [a,b] -> (fromJust . listTup . map ( read @ Int ) . splitOn " - " <$> lines a, read @ Int <$> lines b)
5961 , sShow = show
6062 , sSolve =
61- noFail $
62- id
63+ noFail \ (ranges, xs) ->
64+ countTrue (\ x -> any (`inRange` x) ranges) xs
65+ -- let allRange = foldMap (IS.fromRange) ranges
66+ -- in IS.size $ IS.fromList xs `IS.intersection` allRange
6367 }
6468
6569day05b :: _ :~> _
@@ -68,6 +72,8 @@ day05b =
6872 { sParse = sParse day05a
6973 , sShow = show
7074 , sSolve =
71- noFail $
72- id
75+ noFail \ (ranges, _) -> sum . map ( succ . I. width) . IVS. toAscList $ foldMap ( \ (x,y) -> IVS. singleton $ Finite x I. <=..<= Finite y) ranges
76+ -- countTrue (\x -> any (`inRange` x) ranges) xs
7377 }
78+
79+ -- 402
0 commit comments