Exemplo n.º 1
0
def remove_impossible_candidates(grid: List[List[int]], candidates: List[List[str]]):
    """
    Author: Ayberk
    removes the Impossible candidates in the cell
    :param grid: prints the grid
    :param candidates: the candidates of the cell
    :return: returns the digits that are not removed
    """
    for a in range(0, 8):
        for b in range(0, 8):
            if grid[a][b] != 0:
                List = str()
            else:
                if allanswer == True:
                    List.remove(digit)
    return List
Exemplo n.º 2
0
def min_difference(a_list: typing.List, b_list: typing.List) -> typing.List:
    """
    计算两个列表的最小正数差值 b-a
    :param a_list: 数值列表1
    :param b_list: 数值列表2
    :return:
    """
    # 排序
    a_list.sort()
    b_list.sort()
    # 没有数据 终止
    if len(a_list) == 0 or len(b_list) == 0:
        return []

    # 没有一个a小于b
    if a_list[0] > b_list[-1]:
        return []

    ret_dict = {}
    # 遍历b数组
    for _b in b_list:
        for _a in a_list:
            _diff = _b - _a  # 计算差值
            # 如果差值合理
            if _diff > 0:
                # 记录数值组合
                if _diff in ret_dict:
                    ret_dict[_diff].append((_a, _b))
                else:
                    ret_dict[_diff] = [(_a, _b)]
    # 字典键排序
    _key_list = sorted(ret_dict)
    # 获取差值最小的数据组 可能有多个
    ret_list = ret_dict[_key_list[0]]
    # 清除以选中的数据组
    for _a, _b in ret_list:
        a_list.remove(_a)
        b_list.remove(_b)
    # 如果两个列表都有数据
    if len(a_list) > 0 and len(b_list) > 0:
        ret_list += min_difference(a_list=a_list, b_list=b_list)  # 递归
        ret_list.sort(key=lambda _a: _a[0])  # 按a数据排序
        return ret_list
    else:
        ret_list.sort(key=lambda _a: _a[0])  # 按a数据排序
        return ret_list  # 返回最小的额组合
Exemplo n.º 3
0
def pick_element(a_list: typing.List, remove: bool = False):
    element = random.choice(a_list)
    if remove:
        a_list.remove(element)
    return element
Exemplo n.º 4
0
def pick_element(a_list: typing.List,
                 remove: bool=False):
    element = random.choice(a_list)
    if remove:
        a_list.remove(element)
    return element