AoC/2019/day9/day9.hs

34 lines
795 B
Haskell
Raw Normal View History

2019-12-11 20:21:55 +01:00
module Main where
2019-12-09 10:31:36 +01:00
2019-12-11 20:21:55 +01:00
import Intcode
import Data.List.Split
import qualified Data.Vector as V
2019-12-09 10:31:36 +01:00
2019-12-11 20:21:55 +01:00
main :: IO ()
2019-12-09 10:31:36 +01:00
main = do
2019-12-11 20:21:55 +01:00
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