Skip to content

Commit

Permalink
feat(2017.08-haskell): solve Part Two
Browse files Browse the repository at this point in the history
  • Loading branch information
yurrriq committed Jul 22, 2024
1 parent 3ccc4cc commit cc980f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023.6.2.24
2023.6.2.25
11 changes: 10 additions & 1 deletion src/AdventOfCode/Year2017/Day08.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ partOne = maximum . Map.elems . foldl' go Map.empty
else mem

partTwo :: [Instruction] -> Int
partTwo = undefined
partTwo = maximum . map (maximum . Map.elems) . init . foldl' go [Map.empty]
where
go (mem : history) (Ins op regAlter delta cmp regCompare comparate) =
mem' : mem : history
where
mem' =
if compareReg mem cmp regCompare comparate
then Map.alter (Just . flip (binOp op) delta . fromMaybe 0) regAlter mem
else mem
go [] _ = []

getInput :: IO [Instruction]
getInput = parseInput (some instruction) $(inputFilePath)
Expand Down

0 comments on commit cc980f0

Please sign in to comment.