Skip to content

Instantly share code, notes, and snippets.

@gati
Created November 17, 2014 01:59
Show Gist options
  • Save gati/c0e72ef83e03295cfa82 to your computer and use it in GitHub Desktop.
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.
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