def discover(self, x, y): for direction in range(1, 5): dx, dy = self.directions[direction] new_x = x + dx new_y = y + dy # if position is already discovered continue if (new_x, new_y) in self.map: continue self.inputs.append(direction) self.numbers, out = Intcode.compute_result(self.numbers, self) self.map[(new_x, new_y)] = out # if we discover a wall we should undo the move if out == 1: self.discover(new_x, new_y) self.inputs.append(self.undo_moves[direction]) self.numbers, out = Intcode.compute_result(self.numbers, self) elif out == 1: self.inputs.append(self.undo_moves[direction]) self.numbers, out = Intcode.compute_result(self.numbers, self)
#split into numbers numbers = lines[0].split(',') #convert to int numbers = [int(i) for i in numbers] #extend list numbers.extend([0] * EXTEND) #compute result part 1 tractor_beam = TractorBeam() for i in range(MAX_PART1): for j in range(MAX_PART1): numbers_copy = tractor_beam.compute_input(numbers, i, j) if Intcode.compute_result(numbers_copy, tractor_beam) == 1: tractor_beam.part1 += 1 print("\nPart1: " + str(tractor_beam.part1)) #compute result part 2 y = 99 x = 0 # loop until you can make a square 100x100 full of 1 while True: numbers_copy = tractor_beam.compute_input(numbers, x, y) #Step1: find a line with 100 "pulled by something" responses while Intcode.compute_result(numbers_copy, tractor_beam) == 0: x += 1 numbers_copy = tractor_beam.compute_input(numbers, x, y) #Step2: check if you cand make a square. check if above corner contain 1 x2 = x + 99
print(message[i * SIZE_COL + j], end='') print('') if __name__ == "__main__": with open("input", 'r') as input: lines = input.read().splitlines() #split into numbers numbers = lines[0].split(',') #convert to int numbers = [int(i) for i in numbers] #extend list numbers.extend([0] * EXTEND) numbers_part2 = numbers[:] # part 1 robo = Robot() #compute result robo = Intcode.compute_result(numbers, robo, 0) print("\n Part 1: " + str(len(robo.painted))) # part 2 robo = Robot() #compute result robo = Intcode.compute_result(numbers_part2, robo, 1) print(" Part 2: " + str(len(robo.painted))) robo.part2()
if __name__ == "__main__": with open("input", 'r') as input: lines = input.read().splitlines() #split into numbers numbers = lines[0].split(',') #convert to int numbers = [int(i) for i in numbers] #extend list numbers.extend([0] * EXTEND) #make a copy for part2 numbers_part2 = numbers[:] #compute part1 output = Intcode.compute_result(numbers, None) lines, cols = print_path(output) matrix = compute_matrix(output, lines, cols) intersections = find_intersections(matrix, lines, cols) part1 = compute_part1(intersections) print("\nPart1: " + str(part1) + "\n") #compute part2 numbers_part2[0] = 2 input_list = compute_input_part2() output = Intcode.compute_result(numbers_part2, input_list) lines, cols = print_path(output)
# day 13 import Intcode EXTEND = 1000 if __name__ == "__main__": with open("input", 'r') as input: lines = input.read().splitlines() #split into numbers numbers = lines[0].split(',') #convert to int numbers = [int(i) for i in numbers] #extend list numbers.extend([0] * EXTEND) #make a copy for part2 numbers_part2 = numbers[:] #compute result part 1 part1, _ = Intcode.compute_result(numbers) print("\nPart1: " + str(part1)) #compute result part 2 numbers_part2[0] = 2 _, part2 = Intcode.compute_result(numbers_part2) print("Part2: " + str(part2) + "\n")