编辑代码

from itertools import product

# 提供的数字范围,每个位置的集合
provided_digits_str = "125678	01369	02347	012589"
provided_digits = [set(map(int, digits)) for digits in provided_digits_str.split()]

# 全部数字范围
all_digits = set(range(10))

# 初始化字典存储结果
combinations = {i: [] for i in range(5)}  # 0 到 4 (最多 4 个位置)

# 遍历所有可能的组合
for combo in product(all_digits, repeat=4):
    matched_positions = 0
    for i, digit in enumerate(combo):
        if digit in provided_digits[i]:
            matched_positions += 1
    if matched_positions == 4:  # 值4的特殊情况:每个位置必须取自提供的数字
        if all(combo[i] in provided_digits[i] for i in range(4)):
            combinations[4].append("".join(map(str, combo)))
    else:
        combinations[matched_positions].append("".join(map(str, combo)))

# 直接打印结果
for value, combo_list in combinations.items():
    print(f"Value {value}:")
    print(" ".join(combo_list))
    print()