AoC/2019/day9/day9.hs
2019-12-12 17:43:55 +01:00

33 lines
887 B
Haskell

module Main where
import Intcode
import Data.List.Split
import qualified Data.Vector as V
main :: IO ()
main = do
content <- readFile "input"
let program = V.fromList $ concatMap (map read . splitOn ",") (lines content)
let run x =
runIntcode
(TM
{ tape = tapePreprocess program
, pointer = 0
, pointerOffset = 0
, output = []
, input = Nothing
, state = Continue
}) x
let out1 = output $ run $ Just 1
let out2 = output $ run $ Just 2
print $
concat
["Part 1: " ++ show a ++ ", Part 2: " ++ show b | a <- out1, b <- out2]
runIntcode :: TuringMachine -> Maybe Integer -> TuringMachine
runIntcode tm x = case state tmNew of
Continue -> runIntcode tmNew x
AwaitInput -> runIntcode (tmNew{input = x}) x
_ -> tmNew
where tmNew = execSteps tm