Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
52
Task/Unprimeable-numbers/Python/unprimeable-numbers.py
Normal file
52
Task/Unprimeable-numbers/Python/unprimeable-numbers.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
from itertools import count, islice
|
||||
|
||||
def primes(_cache=[2, 3]):
|
||||
yield from _cache
|
||||
for n in count(_cache[-1]+2, 2):
|
||||
if isprime(n):
|
||||
_cache.append(n)
|
||||
yield n
|
||||
|
||||
def isprime(n, _seen={0: False, 1: False}):
|
||||
def _isprime(n):
|
||||
for p in primes():
|
||||
if p*p > n:
|
||||
return True
|
||||
if n%p == 0:
|
||||
return False
|
||||
|
||||
if n not in _seen:
|
||||
_seen[n] = _isprime(n)
|
||||
return _seen[n]
|
||||
|
||||
def unprime():
|
||||
for a in count(1):
|
||||
d = 1
|
||||
while d <= a:
|
||||
base = (a//(d*10))*(d*10) + (a%d) # remove current digit
|
||||
if any(isprime(y) for y in range(base, base + d*10, d)):
|
||||
break
|
||||
d *= 10
|
||||
else:
|
||||
yield a
|
||||
|
||||
|
||||
print('First 35:')
|
||||
print(' '.join(str(i) for i in islice(unprime(), 35)))
|
||||
|
||||
print('\nThe 600-th:')
|
||||
print(list(islice(unprime(), 599, 600))[0])
|
||||
print()
|
||||
|
||||
first, need = [False]*10, 10
|
||||
for p in unprime():
|
||||
i = p%10
|
||||
if first[i]: continue
|
||||
|
||||
first[i] = p
|
||||
need -= 1
|
||||
if not need:
|
||||
break
|
||||
|
||||
for i,v in enumerate(first):
|
||||
print(f'{i} ending: {v}')
|
||||
Loading…
Add table
Add a link
Reference in a new issue