Created
November 17, 2014 01:59
-
-
Save gati/c0e72ef83e03295cfa82 to your computer and use it in GitHub Desktop.
Get the largest factor a number that's less than a threshold. Useful for finding the best number for breaking a list up into groups of equal size.
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 math | |
""" | |
Get the largest factor a number that's less than a threshold. Useful for finding the | |
best number for breaking a list up into groups of equal size. | |
""" | |
def largest_factor(num, cur=1, factor=1, max_size=10): | |
factor = math.ceil(float(num) / cur) | |
if factor > max_size: | |
return best_factor(arr, cur + 1, int(factor), max_size) | |
else: | |
return int(factor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment