Advent of Code 2019 Repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
642B

  1. import System.Environment
  2. import qualified Data.Map.Strict as Map
  3. import Intcode
  4. computeTilHalt2 :: ((Map.Map Int Int, Int, Int), ([Int], [Int])) -> Int
  5. computeTilHalt2 ((prog, y, z), io) =
  6. if y == -1 then prog Map.! 0
  7. else computeTilHalt2 $ compute (prog, y, z) io
  8. findParams :: Int -> Int
  9. findParams goal = 100*first + second
  10. where
  11. first = (goal-493708) `div` 243000
  12. second = goal - 493708 - 243000*first
  13. main = do
  14. input <- getArgs
  15. let parsed = parseProg $ input!!0
  16. let map = Map.insert 1 12 parsed
  17. let newMap = Map.insert 2 2 map
  18. print $ computeTilHalt2 $ startingState newMap []
  19. print $ findParams 19690720