Last active
February 26, 2019 13:48
-
-
Save lucasamparo/c435921036806e0b7698f99422e3bfd2 to your computer and use it in GitHub Desktop.
A code snippet to pick the set of divisor from a number, with or without limit the largest possible value. Enjoy, if useful.
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
import numpy as np | |
def pick_divisors(value, max_divisor=None): | |
divisors = [] | |
calc_value = np.int0(np.sqrt(value)) | |
limit = calc_value if max_divisor is None else min(max_divisor, calc_value) | |
for i in range(1, limit): | |
if value % i == 0: | |
divisors.append(i) | |
return divisors | |
print(pick_divisors(1000, 100)) | |
print(pick_divisors(129030198, 2000)) | |
print(pick_divisors(1349586)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment