13 lines
442 B
Haskell
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
|