Skip to content

Instantly share code, notes, and snippets.

@be9
Last active December 26, 2015 09:49
Show Gist options
  • Select an option

  • Save be9/7131763 to your computer and use it in GitHub Desktop.

Select an option

Save be9/7131763 to your computer and use it in GitHub Desktop.
1. Find the row (i-th) with max total width
2. Sort the images, so that widest goes first and narrowest last.
3. Loop for all images in i-th starting from widest (image A):
4. For each other row (j-th):
5. Try to move image A to j-th row. That is, if TotalSize[j] + width[A] < TotalSize[i], move and stop. Improvement done.
6. Loop from narrowest to widest image in j-th row (image B):
7. if max(TotalSize[j] - width[B] + width[A], TotalSize[i] - width[A] + width[B]) < TotalSize[i]
then swap image A and image B. Improvement done.
8. If no move nor swap could be made during the run, the split is "unimprovable".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment