<commit_before>#!/usr/bin/env python
__author__ = 'toly'

import time

from base import Figure, init_board, set_figure, get_free_cell, print_board, pprint_board
from settings import WIDTH, HEIGHT, FIGURES_RAW


def make_decisions(board, width, height, figures_dict):

    if not figures_dict:
        yield board
        return

    x, y = get_free_cell(board, width, height)

    for figure_color, figures_list in figures_dict.items():
        for figure in figures_list:

            current_board = set_figure(board, width, height, figure, figure_color, x=x-figure.shift, y=y)

            if current_board is None:
                continue

            current_figures_dict = dict(figures_dict)
            del current_figures_dict[figure_color]

            for decision_board in make_decisions(current_board, width, height, current_figures_dict):
                if not decision_board is None:
                    yield decision_board


if __name__ == '__main__':
    board = init_board(WIDTH, HEIGHT)
    figures_dict = Figure.generate_figures_dict(FIGURES_RAW)

    # board = set_figure(board, WIDTH, HEIGHT, figures_dict[13][0], 13, 3, 3)
    # del figures_dict[13]

    time_start0 = time.time()
    time_start = time_start0

    n = 0
    for decision in make_decisions(board, WIDTH, HEIGHT, figures_dict):
        time_solve = time.time() - time_start
        n += 1
        print 'decision #%d' % n
        print 'solved by %f seconds' % time_solve

        pprint_board(decision)

        # if n >= 10:
        #     break

        time_start = time.time()

    print 'total time:', time.time() - time_start0<commit_msg>small refactor<commit_after>#!/usr/bin/env python
__author__ = 'toly'

import time

from base import Figure, init_board, set_figure, get_free_cell, print_board, pprint_board
from settings import WIDTH, HEIGHT, FIGURES_RAW


def main():
    board = init_board(WIDTH, HEIGHT)
    figures_dict = Figure.generate_figures_dict(FIGURES_RAW)

    # board = set_figure(board, WIDTH, HEIGHT, figures_dict[13][0], 13, 3, 3)
    # del figures_dict[13]

    time_start0 = time.time()
    time_start = time_start0

    n = 0
    for decision in make_decisions(board, WIDTH, HEIGHT, figures_dict):
        time_solve = time.time() - time_start
        n += 1
        print 'decision #%d' % n
        print 'solved by %f seconds' % time_solve

        pprint_board(decision)

        # if n >= 10:
        #     break

        time_start = time.time()

    print 'total time:', time.time() - time_start0


def make_decisions(board, width, height, figures_dict):

    if not figures_dict:
        yield board
        return

    x, y = get_free_cell(board, width, height)

    for figure_color, figures_list in figures_dict.items():
        for figure in figures_list:

            current_board = set_figure(board, width, height, figure, figure_color, x=x-figure.shift, y=y)

            if current_board is None:
                continue

            current_figures_dict = dict(figures_dict)
            del current_figures_dict[figure_color]

            for decision_board in make_decisions(current_board, width, height, current_figures_dict):
                if not decision_board is None:
                    yield decision_board


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.08652094717668488, 'fraction_numerical': 0.009714632665452338, 'mean_word_length': 2.6815642458100557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3051710', 'n_tokens_mistral': 1089, 'n_tokens_neox': 999, 'n_words': 273}