给定一个模式,我们需要通过填充模式中缺少的位置来生成所有可能的二进制数0 and 1.
例如
Pattern = "x1x";
Run Code Online (Sandbox Code Playgroud)
输出:
010
110
011
111
Run Code Online (Sandbox Code Playgroud)
这是相对简单的递归,不需要使用库:
def process(patt):
if "x" not in patt:
print(patt)
else:
process(patt.replace("x", "0", 1))
process(patt.replace("x", "1", 1))
process("x1x")
Run Code Online (Sandbox Code Playgroud)
OUTPUT
010
011
110
111
Run Code Online (Sandbox Code Playgroud)