def solve(): input = read_file("06") points = [tuple(get_ints(line)) for line in input] x_coords, y_coords = list(zip(*points)) top, left, bottom, right = min(y_coords), min(x_coords), max( y_coords), max(x_coords) return sum( sum(abs(point[0] - x) + abs(point[1] - y) for point in points) < 10000 for x in range(left, right + 1) for y in range(top, bottom + 1))
def solve(): players, last_marble = get_ints(read_file("09")) scores = [0] * players field = deque([0]) for current_marble in range(1, last_marble + 1): if not current_marble % 23: field.rotate(7) scores[current_marble % players] += current_marble + field.pop() field.rotate(-1) else: field.rotate(-1) field.append(current_marble) return max(scores)
def solve(): input = [get_ints(line) for line in read_file("03")] field = defaultdict(int) for line in input: c_x, c_y, l_x, l_y = line[1:] for x_pos in range(l_x): for y_pos in range(l_y): field[(x_pos + c_x, y_pos + c_y)] += 1 for line in input: c_num, c_x, c_y, l_x, l_y = line if not sum(field[(x_pos + c_x, y_pos + c_y)] > 1 for x_pos in range(l_x) for y_pos in range(l_y)): return c_num
def solve(): points = [get_ints(line) for line in read_file("10")] found, size = 0, 200 while found < len(points): found = 0 for point in points: point[0] += point[2] point[1] += point[3] if point[0] >= 0 and \ point[0] < size and \ point[1] >= 0 and \ point[1] < size: found += 1 return points
def solve(): input = read_file("06") points = [tuple(get_ints(line)) for line in input] sizes = defaultdict(int) blacklist = set() x_coords, y_coords = zip(*points) top, left, bottom, right = min(y_coords), min(x_coords), max( y_coords), max(x_coords) for x in range(left, right + 1): for y in range(top, bottom + 1): closest_point = get_closest_point((x, y), points) sizes[closest_point] += 1 if x == left or x == right or y == top or y == bottom: blacklist.add(closest_point) return max(size for point, size in sizes.items() if point and point not in blacklist)
global index, input nc = input[(index := index + 1)] nm = input[(index := index + 1)] children = [get_tree() for _ in range(nc)] meta = [input[(index := index + 1)] for _ in range(nm)] return (children, meta) def get_value(tree): children, meta = tree if not len(children): return sum(meta) return sum(get_value(children[m - 1]) for m in meta if m <= len(children)) @timer def solve(): root = get_tree() return get_value(root) index = -1 input = get_ints(read_file("08")) result = solve() print(f"Solution: {result}")