def scan(start_x, end_x, start_y, end_y): coord_iter, _coord_iter = tee( product(range(start_x, end_x), range(start_y, end_y))) inputf = chain.from_iterable(_coord_iter).__next__ map_map = String2DBuilder() count = 0 def outputf(val): nonlocal count if val == 1: count += 1 map_map[next(coord_iter)] = '#' else: next(coord_iter) while True: try: machine = Machine(_prog[:], inputf=inputf, outputf=outputf) run(machine) except StopIteration: break map_map.print() print(count)
elif i == 1: y = output i = 2 elif i == 2: if x == -1 and y == 0: print("Score! {}".format(output)) else: screen[(x, y)] = out_to_str[output] i = 0 return parse_output def take_input(_screen): # sleep(0.1) print(_screen.build()) for (pos, tile) in _screen.items(): if tile == out_to_str[3]: paddle_pos = pos elif tile == out_to_str[4]: ball_pos = pos return ball_pos[0] - paddle_pos[0] if __name__ == '__main__': _screen = String2DBuilder() parse = gen_parser(_screen) prog_mem[0] = 2 run(Machine(prog_mem, outputf=parse, inputf=lambda: take_input(_screen))) print(len(list(filter(lambda x: x == 2, _screen.values()))))
print("Trying guess {}".format(current_guess)) l_in = found_lower r_in = found_lower new_guess_x, new_guess_y = current_guess guess_buffer.extend((new_guess_x, new_guess_y + s - 1, new_guess_x + s - 1, new_guess_y)) print(guess_buffer[0], end='\t') yield guess_buffer.popleft() def outputf(val): global is_l if is_l: global l_in l_in = val == 1 is_l = False else: global r_in r_in = val == 1 is_l = True while final_guess is None: machine = Machine(_prog[:], inputf=inputf().__next__, outputf=outputf) run(machine) print() print(final_guess) scan(final_guess[0], final_guess[0] + s, final_guess[1], final_guess[1] + s) scan(final_guess[0] - 1, final_guess[0] + s - 1, final_guess[1] - 1, final_guess[1] + s - 1)
class Map: _map: {(int, int): int} = dict() _tree_map: {} cam_pos: (int, int) = (0, 0) pos: (int, int) __string_builder = String2DBuilder() scaffold_list: [(int, int)] = [] def process_output(self, out): self._map[self.cam_pos] = out if out != NEW_LINE: if out in VAC: self.pos = self.cam_pos self.__string_builder[self.cam_pos] = chr(out) self.cam_pos = self.cam_pos[0] + 1, self.cam_pos[1] else: self.cam_pos = 0, self.cam_pos[1] + 1 @staticmethod def neighbours(pos): return iter(map(lambda x: (pos[0] + x[0], pos[1] + x[1]), ((0, 1), (1, 0), (0, -1), (-1, 0)))) def alignment_para_sum(self): count = 0 for pos in self._map: if (self._map[pos] in GROUND) and all( map(lambda x: (x in self._map) and (self._map[x] in GROUND), Map.neighbours(pos))): count += pos[0] * pos[1] return count def print(self): print(self.__string_builder.build()) def make_scaffold_list(self): for pos in self._map: if self._map[pos] == SCAFFOLD: self.scaffold_list.append(pos) def make_tree_map(self): def paths(self): self.make_scaffold_list() paths = [] while True: to_visit = set(self.scaffold_list) pos = self.pos dir = (0, 1) while len(to_visit) > 0: for neighbour in Map.neighbours(pos): if def determine_path_functions(self): if __name__ == '__main__': machine_map = Map() machine = Machine(prog[:], outputf=machine_map.process_output) run(machine) machine_map.print() print(machine_map.alignment_para_sum()) _prog = prog[:] _prog[0] = 2 machine = Machine(_prog, outputf=machine_map.process_output)