2019 - Day 5 (Sunny with a Chance of Asteroids)

View puzzle description on AdventOfCode.com
Part 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3

#Advent of Code
#2019 Day 5, Part 1
#Solution by James C. (https://github.com/JamesMCo)

import os, sys
sys.path.append(os.path.abspath("../.."))
import unittest, util.read
from util.tests import run

from util.intcode_2019 import IntcodeComputer

def solve(puzzle_input):
    return IntcodeComputer().load_memory(puzzle_input).queue_inputs(1).run().outputs[-1]

def main():
    puzzle_input = util.read.as_int_list(",")

    diag_code = solve(puzzle_input)

    print("The diagnostic code the program produces is " + str(diag_code) + ".")

class AOC_Tests(unittest.TestCase):
    @unittest.skip("No test cases")
    def test_ex1(self):
        pass

if __name__ == "__main__":
    run(main)
Part 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3

#Advent of Code
#2019 Day 5, Part 2
#Solution by James C. (https://github.com/JamesMCo)

import os, sys
sys.path.append(os.path.abspath("../.."))
import unittest, util.read
from util.tests import run

from util.intcode_2019 import IntcodeComputer

def solve(puzzle_input):
    return IntcodeComputer().load_memory(puzzle_input).queue_inputs(5).run().outputs[-1]

def main():
    puzzle_input = util.read.as_int_list(",")

    diag_code = solve(puzzle_input)

    print("The diagnostic code the program produces is " + str(diag_code) + ".")

class AOC_Tests(unittest.TestCase):
    @unittest.skip("No test cases")
    def test_ex1(self):
        pass

if __name__ == "__main__":
    run(main)
Return to solution index