fork download
  1. # your code goes here
Success #stdin #stdout 0.07s 14052KB
stdin
import itertools

# 定义可用数字(1-9)
digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]

# 生成所有4个不同数字的组合
combinations = list(itertools.combinations(digits, 4))

# 生成所有排列(即密码)
passwords = []
for combo in combinations:
    permutations = list(itertools.permutations(combo))
    for perm in permutations:
        # 将元组转换为整数(如(1,2,3,4) -> 1234)
        password = int(''.join(map(str, perm)))
        passwords.append(password)

# 排序并打印(可选)
passwords.sort()
for p in passwords:
    print(p)

# 打印总数
print(f"总密码数: {len(passwords)}")
stdout
Standard output is empty