def print_date_history(): date = input('Podaj datę w formacie YYYY-MM-DD: ') try: datetime.datetime.strptime(date, '%Y-%m-%d') except ValueError: print('Błędny format daty') return lines = read_lines() date_lines = [] should_aggregate = False for line in lines: if line == ('== ' + date + ' ==\n'): should_aggregate = True elif line.startswith('=='): should_aggregate = False elif should_aggregate: date_lines.append(line) if len(date_lines) > 0: print("Operacje z dnia " + date + ":") for line in date_lines: print(line) else: print("Brak operacji z dnia " + date + ":")
def print_current_session(): lines = read_lines() current_session_lines = [] for line in reversed(lines): if line.startswith('=='): break current_session_lines.append(line) if len(current_session_lines) > 0: print("Operacje w obecnej sesji:") for line in reversed(current_session_lines): print(line) else: print("Brak operacji w obecnej sesji.")
def _get_im_paths(self, split): if split == 'train': im_paths = sorted([osp.join(self.root, 'MSMT17_V1', 'train', l.split(' ')[0]) for l in read_lines(osp.join(self.root, 'MSMT17_V1/list_train.txt'))]) + sorted([osp.join(self.root, 'MSMT17_V1', 'train', l.split(' ')[0]) for l in read_lines(osp.join(self.root, 'MSMT17_V1/list_val.txt'))]) elif split == 'query': im_paths = sorted([osp.join(self.root, 'MSMT17_V1', 'test', l.split(' ')[0]) for l in read_lines(osp.join(self.root, 'MSMT17_V1/list_query.txt'))]) elif split == 'gallery': im_paths = sorted([osp.join(self.root, 'MSMT17_V1', 'test', l.split(' ')[0]) for l in read_lines(osp.join(self.root, 'MSMT17_V1/list_gallery.txt'))]) else: ValueError('Invalid split {}'.format(split)) return im_paths
detectable_asteroids = set() for n in range(0, len(asteroid_map)): for m in range(0, len(asteroid_map[i])): if asteroid_map[n][m]: slope = get_slope(x - n, y - m) if slope not in detectable_asteroids: logging.debug("Found visible asteroid %s, %s" % (n, m)) detectable_asteroids.add(slope) else: logging.debug("Asteroid %s, %s is not visible - slope is %s, %s" % (n, m, slope[0], slope[1])) return len(detectable_asteroids) if __name__ == "__main__": lines = file_utils.read_lines("input10.txt") asteroids = [] for i in range(0, len(lines)): asteroids.append([]) for j in range(0, len(lines[i])): asteroids[i].append(lines[i][j] == "#") max_detectable = -1 for i in range(0, len(asteroids)): for j in range(0, len(asteroids[i])): logging.info("Checking %s, %s" % (i, j)) if asteroids[i][j]: num = find_detectable_asteroids(asteroids, i, j) - 1 logging.info("Found %s visible asteroids" % num) if num > max_detectable:
def calculate_steps_for_points(wire, control_points): step_count = 0 control_point_map = {} for line in wire: points = get_points_on_line(line, control_points) for point in points: residual_distance = get_residual_distance(line, point) control_point_map[point] = step_count + residual_distance step_count += line.length return control_point_map if __name__ == "__main__": wires = file_utils.read_lines("input03.txt") wire1 = day3.puzzle1.get_all_lines(wires[0]) wire2 = day3.puzzle1.get_all_lines(wires[1]) intersections = list( filter(None, [ simple_line.get_intersection(l1, l2) for l1 in wire1 for l2 in wire2 ])) nonzero_intersecting_points = [ point for point in intersections if point != Point(0, 0) ] wire1_map = calculate_steps_for_points(wire1, nonzero_intersecting_points) wire2_map = calculate_steps_for_points(wire2, nonzero_intersecting_points)
def get_multiplier_for_ingredient(item, recipes): recipe = [recipes[r] for r in recipes if r.name == item.chemical.name][0] result_count = recipe.result.count return math.ceil(item.count / result_count) def find_active_chemical(recipes): for chemical in recipes: if chemical not in map( lambda i: i.name, chain.from_iterable([recipes[i].items for i in recipes])): return recipes[chemical] if __name__ == "__main__": lines = file_utils.read_lines("test.txt") recipes = {} parser = parse.Parser("{} => {}") for line in lines: recipe_line = parser.parse(line) result_full = recipe_line[1].split(" ") ingredients = [] for ingredient in recipe_line[0].split(", "): res_full = ingredient.split(" ") ingredients.append(RecipeItem(res_full[1], int(res_full[0]))) main_item = RecipeItem(result_full[1], int(result_full[0])) recipes[main_item.name] = Recipe(main_item, 0 if main_item.name != "FUEL" else 1, ingredients)