Created
November 20, 2012 04:35
-
-
Save jjmalina/4116035 to your computer and use it in GitHub Desktop.
Columns
This file contains hidden or 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
def columns(size, columns=30): | |
""" | |
Return the number of items in each of X columns given a number. | |
Basically the idea is to find exact or next largest rectangle of a given | |
number and given amount of columns. Then fill each column evenly. | |
""" | |
nearest_rect = 0 | |
column_items = [0 for i in xrange(columns)] | |
for index in xrange(columns): | |
if size % columns == 0: | |
nearest_rect = size | |
else: | |
nearest_rect = (size // columns) * columns + columns | |
if index == 0: | |
items = nearest_rect / columns | |
else: | |
items = nearest_rect // columns | |
column_items[index] = items | |
size -= items | |
columns -= 1 | |
return column_items | |
if __name__ == '__main__': | |
for i in range(300): | |
print columns(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment