Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 3, 2024
1 parent 095a30c commit 5937e78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions hs/aoc2024.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ library
base ^>=4.20.0.0,
containers ^>=0.7,
megaparsec ^>=9.7.0,
mtl ^>=2.3.1,
parser-combinators ^>=1.3.0,
text ^>=2.1.1,

Expand Down Expand Up @@ -63,6 +64,7 @@ test-suite aoc2024-test
other-modules:
Day1Spec
Day2Spec
Day3Spec

build-depends:
aoc2024,
Expand Down
11 changes: 4 additions & 7 deletions hs/src/Day3.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{-# LANGUAGE OverloadedStrings #-}

-- |
-- Module: Day3
-- Description: <https://adventofcode.com/2024/day/3 Day 3: Mull It Over>
module Day3 (part1, part2) where

import Control.Monad (filterM)
import Control.Monad.State (MonadState (get, put), evalState)
import Data.Either (rights)
import Data.Functor (($>))
import Data.String (IsString)
import Data.Text (Text)
Expand All @@ -26,8 +27,4 @@ part1 :: Text -> Either (ParseErrorBundle Text Void) Int
part1 = fmap sum . parse parser1 ""

part2 :: Text -> Either (ParseErrorBundle Text Void) Int
part2 = fmap (snd . foldl' go (True, 0)) . parse parser2 ""
where
go (_, a) (Left z) = (z, a)
go (True, a) (Right b) = (True,) $! a + b
go k _ = k
part2 = fmap (sum . rights . flip evalState True . filterM (either (($> False) . put) $ const get)) . parse parser2 ""

0 comments on commit 5937e78

Please sign in to comment.