Created
July 6, 2020 08:58
-
-
Save FirefoxMetzger/9fe0a9cea2399618c67401addb53790c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool, cpu_count | |
from itertools import islice, count | |
def is_special(n, d): | |
tofind = str(d) * d | |
return tofind in str(d * n ** d) | |
def superd(d, N=10000): | |
if d != int(d) or not 2 <= d <= 9: | |
raise ValueError("argument must be integer from 2 to 9 inclusive") | |
with Pool(cpu_count() - 2) as workers: | |
for offset in count(0, N): | |
worker_fn_args = zip(range(offset, offset + N), [d] * N) | |
is_superd_batch = workers.starmap(is_special, worker_fn_args) | |
yield from [n+offset for n in range(N) if is_superd_batch[n]] | |
if __name__ == '__main__': | |
for d in range(2, 10): | |
print(f"{d}:", ', '.join(str(n) for n in islice(superd(d), 10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment