<commit_before>from itertools import islice

def window(seq, n=2):
    "Returns a sliding window (of width n) over data from the iterable"
    "   s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ...                   "
    it = iter(seq)
    result = tuple(islice(it, n))
    if len(result) == n:
        yield result
    for elem in it:
        result = result[1:] + (elem,)
        yield result

def diag_grid_gen(grid):
    def diag_row_gen(x, y, max_x):
        while x < max_x and y >= 0:
            cell = grid[y][x]
            yield cell
            y -= 1
            x += 1
    for i in range(3, len(grid) + len(grid[0]) - 4):
        if i >= len(grid):
            y = len(grid) - 1
        else:
            y = i
        x = i - y
        yield diag_row_gen(x, y, len(grid[0]))

def play(grid, column, color):
    grid = [x[:] for x in grid]
    for row in reversed(grid):
        if row[column] == 0:
            row[column] = color
            return grid
    # Can't play there
    return None

def nodes(grid, player):
    for i in range(len(grid[0])):
        new_grid = play(grid, i, player)
        if new_grid:
            yield i, new_grid<commit_msg>consider the middle positions first<commit_after>from itertools import islice

def window(seq, n=2):
    "Returns a sliding window (of width n) over data from the iterable"
    "   s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ...                   "
    it = iter(seq)
    result = tuple(islice(it, n))
    if len(result) == n:
        yield result
    for elem in it:
        result = result[1:] + (elem,)
        yield result

def diag_grid_gen(grid):
    def diag_row_gen(x, y, max_x):
        while x < max_x and y >= 0:
            cell = grid[y][x]
            yield cell
            y -= 1
            x += 1
    for i in range(3, len(grid) + len(grid[0]) - 4):
        if i >= len(grid):
            y = len(grid) - 1
        else:
            y = i
        x = i - y
        yield diag_row_gen(x, y, len(grid[0]))

def play(grid, column, color):
    grid = [x[:] for x in grid]
    for row in reversed(grid):
        if row[column] == 0:
            row[column] = color
            return grid
    # Can't play there
    return None

def nodes(grid, player):
    l = len(grid[0])
    for i in sorted(range(l), key=lambda x: abs(x - l // 2)):
        new_grid = play(grid, i, player)
        if new_grid:
            yield i, new_grid
{'fraction_non_alphanumeric': 0.13607990012484394, 'fraction_numerical': 0.014565126924677487, 'mean_word_length': 1.6711111111111112, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7258362', 'n_tokens_mistral': 847, 'n_tokens_neox': 814, 'n_words': 262}