mirror of
https://codeberg.org/JasterV/aoc2024-haskell.git
synced 2026-04-27 02:15:43 +00:00
format day3
This commit is contained in:
parent
48e70ac9db
commit
05900411a2
1 changed files with 8 additions and 6 deletions
14
src/Day3.hs
14
src/Day3.hs
|
|
@ -4,12 +4,6 @@ import Data.Maybe (mapMaybe)
|
||||||
import Text.Read (readMaybe)
|
import Text.Read (readMaybe)
|
||||||
import Text.Regex.TDFA
|
import Text.Regex.TDFA
|
||||||
|
|
||||||
data ProgramState = Enabled | Disabled
|
|
||||||
|
|
||||||
data Program = Program ProgramState Int
|
|
||||||
|
|
||||||
data Instruction = Do | Dont | Mul Int Int
|
|
||||||
|
|
||||||
partOne :: String -> Int
|
partOne :: String -> Int
|
||||||
partOne text = programValue $ foldl runInstruction initProgram $ parseInstructions matches
|
partOne text = programValue $ foldl runInstruction initProgram $ parseInstructions matches
|
||||||
where
|
where
|
||||||
|
|
@ -20,6 +14,14 @@ partTwo text = programValue $ foldl runInstruction initProgram $ parseInstructio
|
||||||
where
|
where
|
||||||
matches = getAllTextMatches (text =~ "do\\(\\)|don't\\(\\)|mul\\([0-9]{1,3},[0-9]{1,3}\\)")
|
matches = getAllTextMatches (text =~ "do\\(\\)|don't\\(\\)|mul\\([0-9]{1,3},[0-9]{1,3}\\)")
|
||||||
|
|
||||||
|
-- Program
|
||||||
|
|
||||||
|
data ProgramState = Enabled | Disabled
|
||||||
|
|
||||||
|
data Program = Program ProgramState Int
|
||||||
|
|
||||||
|
data Instruction = Do | Dont | Mul Int Int
|
||||||
|
|
||||||
initProgram :: Program
|
initProgram :: Program
|
||||||
initProgram = Program Enabled 0
|
initProgram = Program Enabled 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue