Skip to content

Commit e73550d

Browse files
committed
initial solve
1 parent 83d15ad commit e73550d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +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.Day06 (
24-
-- day06a,
25-
-- day06b
24+
day06a,
25+
day06b
2626

2727
)
2828
where
@@ -55,19 +55,29 @@ day06a =
5555
MkSol
5656
{ sParse =
5757
noFail $
58-
lines
58+
map reverse . transpose . map words . lines
5959
, sShow = show
6060
, sSolve =
6161
noFail $
62-
id
62+
sum . map go
6363
}
64+
where
65+
go ("*":xs) = product $ map read xs
66+
go ("+":xs) = sum $ map read xs
6467

6568
day06b :: _ :~> _
6669
day06b =
6770
MkSol
68-
{ sParse = sParse day06a
71+
{ sParse = noFail $
72+
splitWhen (all isSpace) . transpose . lines
6973
, sShow = show
7074
, sSolve =
7175
noFail $
72-
id
76+
sum . map go
7377
}
78+
where
79+
go (x:xs) = case last x of
80+
'*' -> product $ map read (init x : xs)
81+
'+' -> sum $ map read (init x : xs)
82+
83+
-- 14, 148

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
123 328 51 64
2+
45 64 387 23
3+
6 98 215 314
4+
* + * +
5+
>>> 3263827

0 commit comments

Comments
Β (0)