-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay25.hs
21 lines (18 loc) · 840 Bytes
/
Day25.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{-# LANGUAGE OverloadedStrings #-}
-- |
-- Module: Day25
-- Description: <https://adventofcode.com/2024/day/25 Day 25: Code Chronicle>
module Day25 (part1) where
import Control.Arrow (Arrow ((&&&)))
import Data.Function (on)
import Data.List (partition)
import Data.List.NonEmpty (nonEmpty)
import Data.List.NonEmpty qualified as NonEmpty (head)
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import Data.Text qualified as T (group, head, length, lines, splitOn, transpose)
part1 :: Text -> Int
part1 input = length . filter and $ zipWith ((>=) `on` snd) <$> keys <*> locks
where
stanzas = mapMaybe (fmap ((T.head &&& T.length) . NonEmpty.head) . nonEmpty . T.group) . T.transpose . T.lines <$> T.splitOn "\n\n" input
(keys, locks) = partition (maybe False ((== '.') . fst . NonEmpty.head) . nonEmpty) stanzas