Skip to content

Commit

Permalink
Merge pull request #39 from ephemient/hs/day4
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient authored Dec 4, 2024
2 parents 18a960a + 4110f43 commit 90e593e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hs/src/Day4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
-- Description: <https://adventofcode.com/2024/day/4 Day 4: Ceres Search>
module Day4 (part1, part2) where

import Control.Monad (ap, guard)
import Data.Function (on)
import Control.Monad (guard)
import Data.List (tails)
import Data.Text (Text)
import Data.Text qualified as T (drop, lines, reverse, splitAt, transpose, unpack, zip)
import Data.Text.Internal.Search qualified as T (indices)

part1 :: Text -> Int
part1 input = sum $ ((+) `on` length . T.indices "XMAS") `ap` T.reverse <$> grid ++ T.transpose grid ++ concat diagonals
part1 input = sum $ countXmas <$> grid ++ T.transpose grid ++ concat diagonals
where
grid = T.lines input
diagonals = do
(lower, upper) <- unzip . zipWith T.splitAt [0 ..] <$> [grid, reverse grid]
T.transpose <$> [T.reverse <$> lower, upper]
countXmas line = length (T.indices "XMAS" line) + length (T.indices "SAMX" line)

part2 :: Text -> Int
part2 input = length $ do
Expand Down

0 comments on commit 90e593e

Please sign in to comment.