From f9c2363ec3f3584c2a720eda436a504ea68e9b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 21 Dec 2019 14:06:57 +0100 Subject: Day 19 --- 19/input/19 | 1 + 19/py/d19.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 19/input/19 create mode 100644 19/py/d19.py (limited to '19') diff --git a/19/input/19 b/19/input/19 new file mode 100644 index 0000000..1d8e0c8 --- /dev/null +++ b/19/input/19 @@ -0,0 +1 @@ +109,424,203,1,21102,1,11,0,1106,0,282,21101,0,18,0,1106,0,259,1202,1,1,221,203,1,21101,0,31,0,1105,1,282,21102,38,1,0,1105,1,259,20102,1,23,2,21201,1,0,3,21102,1,1,1,21101,0,57,0,1105,1,303,2101,0,1,222,20102,1,221,3,21002,221,1,2,21101,0,259,1,21101,0,80,0,1106,0,225,21102,1,152,2,21101,91,0,0,1106,0,303,1201,1,0,223,21001,222,0,4,21101,0,259,3,21102,225,1,2,21101,0,225,1,21102,1,118,0,1105,1,225,20101,0,222,3,21102,61,1,2,21101,133,0,0,1106,0,303,21202,1,-1,1,22001,223,1,1,21102,148,1,0,1105,1,259,2101,0,1,223,21001,221,0,4,21001,222,0,3,21101,0,14,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21101,0,195,0,105,1,109,20207,1,223,2,20101,0,23,1,21102,-1,1,3,21102,214,1,0,1105,1,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2101,0,-4,249,21202,-3,1,1,21202,-2,1,2,21201,-1,0,3,21102,1,250,0,1106,0,225,22101,0,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2105,1,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,22102,1,-2,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,21202,-2,1,3,21101,343,0,0,1106,0,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,22101,0,-4,1,21101,0,384,0,1106,0,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,21201,1,0,-4,109,-5,2106,0,0 diff --git a/19/py/d19.py b/19/py/d19.py new file mode 100644 index 0000000..808e978 --- /dev/null +++ b/19/py/d19.py @@ -0,0 +1,86 @@ +import collections +import intcode +import sys +import time + +def draw(beam): + min_x=max_x=min_y=max_y = 0 + for p in beam: + min_x = min(p[0], min_x) + max_x = max(p[0], max_x) + min_y = min(p[1], min_y) + max_y = max(p[1], max_y) + s = "" + for y in range(min_y, max_y+1): + s += "\n" + for x in range(min_x, max_x+1): + point = (x,y) + if point in beam: + s += "#" if beam[point] else " " + else: + s += "?" + return s + +def deploy(c, x, y): + c.reset() + input = collections.deque((x,y)) + while True: + c.step() + if c.SIG_INPUT: + c.input = input.popleft() + if c.SIG_OUTPUT: + break + return c.output + +def do(input): + amount = 0 + c = intcode.Computer([int(x) for x in input[0].split(",")]) + + # #### 46 + # #### 47 + # #### 48 + # ##### 49 + # #### 50 + + # assume every row has a point. this can be done by starting from row 50 + # (or some other larger enough number) + + # search each row one by one. when the lenght of the row has been + # determined, check the length of the col of every point where the distance + # to the right is greater than 100. if no col longer than 100 is found, + # skip to the next row (and check only starting from the same x as the + # first x of the row above) + + y = 1000 # tested to not be 100 until after row 1000 + start_x = 0 + while True: + found = False + x = start_x + amount_in_row = 0 + while True: + if deploy(c, x, y) == 1: + if not found: + start_x = x + found = True + amount_in_row += 1 + elif found: + break + x += 1 + tries = amount_in_row - 100 + for i in range(0, tries+1): + # check downwards + amount_in_col = 0 + row = y + while True: + if deploy(c, start_x+i, row) == 1: + amount_in_col += 1 + row += 1 + else: + break + if amount_in_col >= 100: + # done + return start_x+i, y + y += 1 + +input = open("../input/19", "r").readlines() +print(do(input)) -- cgit v1.2.1