AoC/2019/day9/day9.hs
shu 345d628347 Day 9: Refactor
We enterprise now
2019-12-11 20:21:55 +01:00

34 lines
795 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 = [x]
, state = Continue
})
let out1 = output $ run 1
let out2 = output $ run 2
print $
concat
["Part 1: " ++ show a ++ ", Part 2: " ++ show b | a <- out1, b <- out2]
runIntcode :: TuringMachine -> TuringMachine
runIntcode tm =
case state tmNew of
Continue -> runIntcode tmNew
_ -> tmNew
where
tmNew = step tm