Skip to content

Commit 255e703

Browse files
committed
initial solve
1 parent a401fea commit 255e703

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

β€Ž2025/AOC2025/Day05.hsβ€Ž

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
-- solution. You can delete the type signatures completely and GHC
2222
-- will recommend what should go in place of the underscores.
2323
module AOC2025.Day05 (
24-
-- day05a,
25-
-- day05b
26-
24+
day05a,
25+
day05b,
2726
)
2827
where
2928

@@ -42,24 +41,29 @@ import qualified Data.OrdPSQ as PSQ
4241
import qualified Data.Sequence as Seq
4342
import qualified Data.Sequence.NonEmpty as NESeq
4443
import qualified Data.Set as S
44+
import Data.ExtendedReal (Extended(..))
4545
import qualified Data.Set.NonEmpty as NES
4646
import qualified Data.Text as T
4747
import qualified Data.Vector as V
4848
import qualified Linear as L
4949
import qualified Text.Megaparsec as P
5050
import qualified Text.Megaparsec.Char as P
5151
import qualified Text.Megaparsec.Char.Lexer as PP
52+
import qualified Data.Interval as I
53+
import qualified Data.IntervalSet as IVS
5254

5355
day05a :: _ :~> _
5456
day05a =
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

6569
day05b :: _ :~> _
@@ -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

β€Žtest-data/2025/05a.txtβ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
3-5
2+
10-14
3+
16-20
4+
12-18
5+
6+
1
7+
5
8+
8
9+
11
10+
17
11+
32
12+
>>> 3

β€Žtest-data/2025/05b.txtβ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
3-5
2+
10-14
3+
16-20
4+
12-18
5+
6+
1
7+
5
8+
8
9+
11
10+
17
11+
32
12+
>>> 14

0 commit comments

Comments
Β (0)