loop through each post to see into which column it should go, then have it
place the post in that column.
But! If you're willing to step a bit outside your specifications in
exchange for much less coding, jQuery Masonry <http://masonry.desandro.com/>does something very similar to what you want.