※ 引述《mikemagic88 (Mikemagic88)》之铭言:
: 使用者输入1 印1-9
: 使用者输入2 印1-98 (11, 22, 33等重复的不印)
: 使用者输入3 印1-987 (121, 988, 667等有重复的不印)
不同的程式语言,提供同一个问题的不同观点:
Python 3:
def has_distinct_digits(n):
return len(set(str(n))) == len(str(n))
def DD_numbers(N):
return [ x for x in range(1, 10**N) if has_distinct_digits(x) ]
R = input('Enter a number : ')
L = DD_numbers(int(R))
print(', '.join(map(str, L)))
======================================================================
执行范例:
Enter a number :2
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64,
65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98