1
0
Fork 0
advent-of-code/2020/day08/part2.hs

13 lines
442 B
Haskell

import Data.Foldable
import qualified Data.IntMap as IntMap
import VM
main = do
instructions <- readInstructions <$> readFile "input"
print . fmap snd . find ((== Halt) . fst) . map vmRun . map (IntMap.adjust swapNopJmp `flip` instructions) $ IntMap.keys instructions
swapNopJmp :: Instruction -> Instruction
swapNopJmp orig@(opcode, value) = case opcode of
"jmp" -> ("nop", value)
"nop" -> ("jmp", value)
otherwise -> orig