def process_one(data): numbers, boards = data called_numbers, rest = numbers[:4], numbers[4:] # Can't win without 5 nums for number in rest: called_numbers.append(number) check = partial(is_winner, called_numbers) if winning_totals := lcompact(lmap(check, boards)): return winning_totals[0]
def get_lows(data): grid = [] gridd = {} for y, row in enumerate(data): for x, char in enumerate(row): grid.append(aoc.Point(x=x, y=y)) gridd[aoc.Point(x=x, y=y)] = (char, None) for pt in gridd: above = gridd.get(aoc.Point(x=pt.x, y=pt.y - 1)) below = gridd.get(aoc.Point(x=pt.x, y=pt.y + 1)) left = gridd.get(aoc.Point(x=pt.x - 1, y=pt.y)) right = gridd.get(aoc.Point(x=pt.x + 1, y=pt.y)) adjs = lcompact([above, below, left, right]) curr = int(gridd[pt][0]) low = True for adj in adjs: if curr >= int(adj[0]): low = False if low: gridd[pt] = (gridd[pt][0], curr + 1) lows = lmap(lambda x: x, lfilter(lambda x: x[1][1] is not None, gridd.items())) return lows
def process_two(data): lines = lcompact(lmap(make_line_diag, data)) count = detect_overlap(lines) return count
def process_one(data): lines = lcompact(lmap(make_line, data)) count = detect_overlap(lines) return count
def process_two(data): lines = lcompact([make_naive_line(ln[0], ln[1], diag=True) for ln in data]) return detect_overlap(lines)
def process_one(data): lines = lcompact(starmap(make_naive_line, data)) return detect_overlap(lines)