2019 - Day 9 šŸŽ‚ (Sensor Boost)

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
31
32
33
34
35
36
#!/usr/bin/env python3

#Advent of Code
#2019 Day 9, 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

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

    keycode = solve(puzzle_input)[-1]

    print("The BOOST keycode the computer produces is " + str(keycode) + ".")

class AOC_Tests(unittest.TestCase):
    def test_ex1(self):
        self.assertEqual(solve([109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99]),
                               [109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99])

    def test_ex2(self):
        self.assertEqual(len(str(solve([1102,34915192,34915192,7,4,7,99, 0])[0])), 16)

    def test_ex3(self):
        self.assertEqual(solve([104, 1125899906842624, 99])[0], 1125899906842624)

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 9, 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(2).run().outputs

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

    coords = solve(puzzle_input)[-1]

    print("The coordinates of the distress signal are " + str(coords) + ".")

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

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