Skip to content

Commit 8a2558e

Browse files
committed
Day 25: Make use of List monad
1 parent 9c48efa commit 8a2558e

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

hs/src/Day25.hs

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module Day25 (part1) where
77

88
import Control.Arrow (Arrow ((&&&)))
9+
import Data.Function (on)
910
import Data.List (partition)
1011
import Data.List.NonEmpty (nonEmpty)
1112
import Data.List.NonEmpty qualified as NonEmpty (head)
@@ -14,13 +15,7 @@ import Data.Text (Text)
1415
import Data.Text qualified as T (group, head, length, lines, splitOn, transpose)
1516

1617
part1 :: Text -> Int
17-
part1 input =
18-
length
19-
[ ()
20-
| key <- keys,
21-
lock <- locks,
22-
and [k >= l | ((_, k), (_, l)) <- zip key lock]
23-
]
18+
part1 input = length . filter and $ zipWith ((>=) `on` snd) <$> keys <*> locks
2419
where
2520
stanzas = mapMaybe (fmap ((T.head &&& T.length) . NonEmpty.head) . nonEmpty . T.group) . T.transpose . T.lines <$> T.splitOn "\n\n" input
2621
(keys, locks) = partition (maybe False ((== '.') . fst . NonEmpty.head) . nonEmpty) stanzas

0 commit comments

Comments
 (0)