diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-23 08:11:19 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2019-12-23 08:12:38 +0100 |
| commit | 7ba3e185247d29560b210848b977cf399f0d9fb7 (patch) | |
| tree | bc8dc2e16897c1b6fa8b2eb93910829e9c81d4cc | |
| parent | ea7a5095ea9765ecc4799fdaf7e95e49dfdc8101 (diff) | |
| download | aoc-7ba3e185247d29560b210848b977cf399f0d9fb7.tar.gz | |
Day 23
| -rw-r--r-- | 19/input/23 | 1 | ||||
| -rw-r--r-- | 19/py/d23.py | 54 | ||||
| -rw-r--r-- | 19/py/intcode.py | 13 |
3 files changed, 63 insertions, 5 deletions
diff --git a/19/input/23 b/19/input/23 new file mode 100644 index 0000000..8703026 --- /dev/null +++ b/19/input/23 @@ -0,0 +1 @@ +3,62,1001,62,11,10,109,2259,105,1,0,1078,1756,645,2121,1119,1859,1412,1954,1251,855,888,608,1183,1554,725,571,921,1521,1313,952,682,2183,820,785,1991,1484,2090,2057,1346,2212,1680,1649,1218,756,1614,1152,983,1828,1721,1047,2026,1014,1791,2152,1923,1282,1890,1377,1583,1445,0,0,0,0,0,0,0,0,0,0,0,0,3,64,1008,64,-1,62,1006,62,88,1006,61,170,1105,1,73,3,65,20101,0,64,1,20101,0,66,2,21101,0,105,0,1106,0,436,1201,1,-1,64,1007,64,0,62,1005,62,73,7,64,67,62,1006,62,73,1002,64,2,133,1,133,68,133,101,0,0,62,1001,133,1,140,8,0,65,63,2,63,62,62,1005,62,73,1002,64,2,161,1,161,68,161,1101,1,0,0,1001,161,1,169,1002,65,1,0,1101,1,0,61,1102,0,1,63,7,63,67,62,1006,62,203,1002,63,2,194,1,68,194,194,1006,0,73,1001,63,1,63,1105,1,178,21101,0,210,0,105,1,69,2102,1,1,70,1102,1,0,63,7,63,71,62,1006,62,250,1002,63,2,234,1,72,234,234,4,0,101,1,234,240,4,0,4,70,1001,63,1,63,1106,0,218,1105,1,73,109,4,21102,0,1,-3,21101,0,0,-2,20207,-2,67,-1,1206,-1,293,1202,-2,2,283,101,1,283,283,1,68,283,283,22001,0,-3,-3,21201,-2,1,-2,1105,1,263,21201,-3,0,-3,109,-4,2106,0,0,109,4,21101,1,0,-3,21101,0,0,-2,20207,-2,67,-1,1206,-1,342,1202,-2,2,332,101,1,332,332,1,68,332,332,22002,0,-3,-3,21201,-2,1,-2,1105,1,312,21201,-3,0,-3,109,-4,2106,0,0,109,1,101,1,68,359,20101,0,0,1,101,3,68,366,21002,0,1,2,21102,376,1,0,1105,1,436,22101,0,1,0,109,-1,2106,0,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21202,-6,10,-5,22207,-7,-5,-5,1205,-5,521,21101,0,0,-4,21101,0,0,-3,21102,51,1,-2,21201,-2,-1,-2,1201,-2,385,470,21002,0,1,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,496,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,515,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,461,1105,1,547,21102,-1,1,-4,21202,-6,-1,-6,21207,-7,0,-5,1205,-5,547,22201,-7,-6,-7,21201,-4,1,-4,1106,0,529,22102,1,-4,-7,109,-8,2105,1,0,109,1,101,1,68,563,21001,0,0,0,109,-1,2106,0,0,1101,34351,0,66,1101,0,4,67,1102,598,1,68,1102,302,1,69,1101,0,1,71,1102,606,1,72,1106,0,73,0,0,0,0,0,0,0,0,25,243092,1101,0,34897,66,1102,4,1,67,1101,635,0,68,1102,302,1,69,1102,1,1,71,1101,643,0,72,1106,0,73,0,0,0,0,0,0,0,0,49,271749,1101,0,37657,66,1102,4,1,67,1102,672,1,68,1102,1,302,69,1102,1,1,71,1101,680,0,72,1106,0,73,0,0,0,0,0,0,0,0,30,15887,1102,6257,1,66,1101,0,1,67,1102,1,709,68,1101,556,0,69,1102,1,7,71,1102,711,1,72,1106,0,73,1,2,7,214077,7,285436,24,145918,15,137404,42,24097,30,47661,30,79435,1101,0,1069,66,1101,1,0,67,1102,1,752,68,1101,0,556,69,1102,1,1,71,1101,754,0,72,1106,0,73,1,160,30,63548,1102,1,25997,66,1101,0,1,67,1101,783,0,68,1102,1,556,69,1102,0,1,71,1102,1,785,72,1105,1,73,1,1275,1102,1,95597,66,1101,3,0,67,1102,812,1,68,1101,302,0,69,1102,1,1,71,1101,818,0,72,1105,1,73,0,0,0,0,0,0,49,181166,1101,96479,0,66,1101,3,0,67,1101,847,0,68,1101,302,0,69,1102,1,1,71,1102,1,853,72,1106,0,73,0,0,0,0,0,0,49,90583,1102,1,90481,66,1101,0,2,67,1102,882,1,68,1102,1,302,69,1102,1,1,71,1101,0,886,72,1106,0,73,0,0,0,0,24,72959,1102,1,40177,66,1102,1,2,67,1101,915,0,68,1102,302,1,69,1101,0,1,71,1101,0,919,72,1105,1,73,0,0,0,0,6,194738,1101,0,67987,66,1101,0,1,67,1101,948,0,68,1101,556,0,69,1102,1,1,71,1102,1,950,72,1105,1,73,1,48,9,180962,1101,87071,0,66,1102,1,1,67,1101,0,979,68,1102,1,556,69,1102,1,1,71,1102,1,981,72,1106,0,73,1,-108,1,35083,1102,1,87481,66,1102,1,1,67,1102,1010,1,68,1102,1,556,69,1101,1,0,71,1101,0,1012,72,1105,1,73,1,1201,23,95597,1102,58573,1,66,1101,1,0,67,1101,0,1041,68,1102,1,556,69,1101,2,0,71,1101,0,1043,72,1106,0,73,1,421,15,34351,1,105249,1102,77569,1,66,1101,0,1,67,1101,1074,0,68,1101,556,0,69,1101,0,1,71,1102,1,1076,72,1105,1,73,1,41,11,104691,1101,0,23473,66,1102,1,1,67,1101,0,1105,68,1101,556,0,69,1101,6,0,71,1101,1107,0,72,1106,0,73,1,25057,46,59053,47,92861,47,185722,38,52571,38,105142,38,157713,1101,4457,0,66,1102,1,1,67,1102,1,1146,68,1101,0,556,69,1102,1,2,71,1102,1,1148,72,1106,0,73,1,3,24,218877,15,68702,1101,0,18973,66,1102,1,1,67,1101,1179,0,68,1101,556,0,69,1102,1,1,71,1101,1181,0,72,1105,1,73,1,-557,22,289437,1101,0,45161,66,1101,0,3,67,1101,1210,0,68,1101,302,0,69,1101,1,0,71,1101,0,1216,72,1105,1,73,0,0,0,0,0,0,49,362332,1102,1,9461,66,1101,2,0,67,1101,0,1245,68,1102,1,302,69,1101,1,0,71,1102,1249,1,72,1106,0,73,0,0,0,0,42,96388,1101,69257,0,66,1102,1,1,67,1102,1,1278,68,1101,556,0,69,1101,0,1,71,1102,1,1280,72,1105,1,73,1,1217,42,72291,1101,2153,0,66,1101,1,0,67,1102,1309,1,68,1101,556,0,69,1102,1,1,71,1101,0,1311,72,1105,1,73,1,81,12,135483,1102,1,44983,66,1102,1,1,67,1102,1,1340,68,1102,1,556,69,1102,1,2,71,1102,1342,1,72,1105,1,73,1,10,2,150628,30,31774,1101,0,50077,66,1102,1,1,67,1102,1,1373,68,1101,556,0,69,1102,1,1,71,1102,1,1375,72,1105,1,73,1,8,42,48194,1101,92861,0,66,1101,0,3,67,1101,1404,0,68,1101,0,302,69,1102,1,1,71,1101,1410,0,72,1105,1,73,0,0,0,0,0,0,25,182319,1102,97369,1,66,1101,2,0,67,1101,0,1439,68,1101,0,302,69,1102,1,1,71,1101,1443,0,72,1105,1,73,0,0,0,0,27,19354,1101,90583,0,66,1101,5,0,67,1102,1,1472,68,1102,1,253,69,1101,0,1,71,1102,1482,1,72,1105,1,73,0,0,0,0,0,0,0,0,0,0,9,90481,1101,60773,0,66,1102,1,4,67,1101,1511,0,68,1101,0,253,69,1101,0,1,71,1102,1,1519,72,1106,0,73,0,0,0,0,0,0,0,0,17,36563,1101,36563,0,66,1102,1,2,67,1102,1548,1,68,1102,351,1,69,1101,1,0,71,1101,1552,0,72,1105,1,73,0,0,0,0,255,23473,1101,29453,0,66,1102,1,1,67,1102,1,1581,68,1101,0,556,69,1102,1,0,71,1102,1583,1,72,1106,0,73,1,1957,1101,57793,0,66,1101,1,0,67,1102,1,1610,68,1102,556,1,69,1101,1,0,71,1101,0,1612,72,1105,1,73,1,125,2,37657,1102,39863,1,66,1102,1,1,67,1102,1,1641,68,1102,556,1,69,1101,0,3,71,1102,1,1643,72,1106,0,73,1,5,2,75314,2,112971,30,95322,1102,1,70289,66,1101,0,1,67,1102,1676,1,68,1102,1,556,69,1101,0,1,71,1101,0,1678,72,1105,1,73,1,1120,23,191194,1101,15887,0,66,1101,6,0,67,1102,1707,1,68,1102,1,302,69,1101,0,1,71,1102,1719,1,72,1106,0,73,0,0,0,0,0,0,0,0,0,0,0,0,17,73126,1102,1,52571,66,1102,3,1,67,1101,0,1748,68,1102,302,1,69,1102,1,1,71,1101,0,1754,72,1105,1,73,0,0,0,0,0,0,25,121546,1101,0,35083,66,1101,0,3,67,1102,1,1783,68,1102,302,1,69,1101,1,0,71,1101,0,1789,72,1106,0,73,0,0,0,0,0,0,47,278583,1102,24097,1,66,1102,1,4,67,1102,1,1818,68,1102,302,1,69,1102,1,1,71,1101,1826,0,72,1105,1,73,0,0,0,0,0,0,0,0,46,118106,1102,1,37483,66,1101,0,1,67,1101,0,1855,68,1101,0,556,69,1102,1,1,71,1102,1857,1,72,1105,1,73,1,2837,12,45161,1102,74653,1,66,1102,1,1,67,1102,1,1886,68,1101,0,556,69,1101,0,1,71,1101,1888,0,72,1106,0,73,1,249,11,139588,1102,59053,1,66,1101,2,0,67,1101,0,1917,68,1102,302,1,69,1101,1,0,71,1101,1921,0,72,1105,1,73,0,0,0,0,25,60773,1102,99173,1,66,1102,1,1,67,1101,0,1950,68,1102,556,1,69,1102,1,1,71,1102,1,1952,72,1106,0,73,1,17,11,34897,1102,1,71359,66,1102,4,1,67,1102,1981,1,68,1101,302,0,69,1101,0,1,71,1102,1,1989,72,1105,1,73,0,0,0,0,0,0,0,0,49,452915,1101,72959,0,66,1102,3,1,67,1102,2018,1,68,1102,1,302,69,1102,1,1,71,1102,2024,1,72,1105,1,73,0,0,0,0,0,0,15,103053,1101,0,76283,66,1101,0,1,67,1101,2053,0,68,1102,1,556,69,1102,1,1,71,1102,2055,1,72,1105,1,73,1,71339,10,40177,1101,0,9677,66,1101,0,2,67,1101,2084,0,68,1101,0,302,69,1102,1,1,71,1102,2088,1,72,1106,0,73,0,0,0,0,32,9461,1102,51871,1,66,1101,0,1,67,1102,1,2117,68,1102,1,556,69,1101,1,0,71,1101,2119,0,72,1105,1,73,1,653,22,96479,1102,96457,1,66,1102,1,1,67,1102,2148,1,68,1102,1,556,69,1102,1,1,71,1102,1,2150,72,1106,0,73,1,89,7,71359,1101,26053,0,66,1101,1,0,67,1102,1,2179,68,1102,1,556,69,1101,0,1,71,1101,0,2181,72,1106,0,73,1,224,7,142718,1102,34369,1,66,1102,1,1,67,1102,1,2210,68,1102,556,1,69,1102,0,1,71,1102,1,2212,72,1105,1,73,1,1626,1101,54151,0,66,1101,0,1,67,1101,2239,0,68,1101,556,0,69,1102,9,1,71,1101,0,2241,72,1105,1,73,1,1,22,192958,11,69794,12,90322,23,286791,10,80354,6,97369,27,9677,32,18922,1,70166 diff --git a/19/py/d23.py b/19/py/d23.py new file mode 100644 index 0000000..14416e9 --- /dev/null +++ b/19/py/d23.py @@ -0,0 +1,54 @@ +import collections +import intcode +import sys + +program = [int(x) for x in open("../input/23", "r").readline().split(",")] + +computers = [intcode.Computer(program, network_id=i) for i in range(50)] +queues = [collections.deque([i]) for i in range(len(computers))] +output_buffers = [[] for _ in range(len(computers))] +waiting = [False for _ in range(len(computers))] + +prev_nat_x, prev_nat_y = -1, -1 +nat_x, nat_y = 0, 0 + +while True: + for i in range(len(computers)): + c = computers[i] + c.step() + if c.SIG_INPUT: + if len(queues[i]) > 0: + c.input = queues[i].popleft() + waiting[i] = False + else: + c.input = -1 + waiting[i] = True + if c.SIG_OUTPUT: + output_buffers[i].append(c.output) + c.output = None + waiting[i] = False + if len(output_buffers[i]) == 3: + addr, x, y = output_buffers[i] + output_buffers[i] = [] + if addr == 255: + nat_x, nat_y = x, y + else: + queues[addr].append(x) + queues[addr].append(y) + empty_queues = True + for q in queues: + if len(q) > 0: + empty_queues = False + break + all_waiting = True + for w in waiting: + if not w: + all_waiting = False + break + if empty_queues and all_waiting: + queues[0].append(nat_x) + queues[0].append(nat_y) + if nat_y == prev_nat_y: + print(nat_y) + sys.exit() + prev_nat_x, prev_nat_y = nat_x, nat_y diff --git a/19/py/intcode.py b/19/py/intcode.py index 843688c..1c0f062 100644 --- a/19/py/intcode.py +++ b/19/py/intcode.py @@ -13,14 +13,17 @@ BAS = 9 HAL = 99 class Computer(object): - def __init__(self, program, ascii=False): + def __init__(self, program, ascii=False, network_id=None): self.program = program self.memory_size = len(self.program) self.instruction_cache = {} - if ascii: - self.SIG_ASCII = True - else: - self.SIG_ASCII = False + + self.SIG_ASCII = ascii + + self.SIG_NET = False + if network_id is not None: + self.SIG_NET = True + self.network_id = network_id self.reset() |
