/
047.py
50 lines (40 loc) · 1.08 KB
/
047.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from primes import factors
def consecutive_distinct(count):
"""
>>> consecutive_distinct(2)
14
>>> consecutive_distinct(3)
644
"""
result = None
acc = set()
consecutive = 1
i = 1
while result is None:
i += 1
new = set(factors(i))
# does i have the correct number of factors
if len(new) != count:
consecutive = 1
acc = set()
continue
# acc is empty and new is acceptable we are resetting
if len(acc) == 0:
consecutive = 1
acc = new
continue
# are all of i's factor distinct from the previous 'count' i
if len(acc.intersection(new)) != 0:
consecutive = 1
acc = new
continue
# increase the count of consecutive and add the factors to acc
consecutive += 1
acc = acc.union(new)
if consecutive == count:
result = i - count + 1
return result
if __name__ == '__main__':
import doctest
doctest.testmod()
print consecutive_distinct(4)