From cc980f097b39196bdfd763e63479fa56ab0e3df0 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 22 Jul 2024 15:25:23 -0500 Subject: [PATCH] feat(2017.08-haskell): solve Part Two --- VERSION | 2 +- src/AdventOfCode/Year2017/Day08.hs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 02a4aff..862e7aa 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2023.6.2.24 \ No newline at end of file +2023.6.2.25 \ No newline at end of file diff --git a/src/AdventOfCode/Year2017/Day08.hs b/src/AdventOfCode/Year2017/Day08.hs index 59a1ced..2a8cd4f 100644 --- a/src/AdventOfCode/Year2017/Day08.hs +++ b/src/AdventOfCode/Year2017/Day08.hs @@ -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)