Skip to content

Instantly share code, notes, and snippets.

@use
Last active August 29, 2015 14:08
Show Gist options
  • Save use/f47bb4e01d13f4ea2144 to your computer and use it in GitHub Desktop.
Save use/f47bb4e01d13f4ea2144 to your computer and use it in GitHub Desktop.
Find candidate thumbnail widths (x) and gap widths (y) with min/max constraints and fixed total width
def thumbnail_width_candidates(mingap, maxgap, minwidth, maxwidth, numitems, totalwidth):
return [
(x, y)
for y in range(mingap, maxgap)
for x in range(minwidth, maxwidth)
if
x%1==0 and
y%1==0 and
x*numitems + y*(numitems-1) == totalwidth
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment