Given the dimensions of two rectangles, i need to know how many smaller rectangles can fit the bigger one. It should account for mixed orientations meaning that the smaller rectangle can both be landscape and portrait when fit inside the bigger rectangle.

Example image

Is there a math equation for this?


  • $\begingroup$ Going by how you've packed the rectangles in your image, it should say $2\times 5$ rectangles, not $3\times 5$. Also, you can fit eight of them in the $7\times 12$ rectangle by packing six along the length $12$ edge, and two more in the leftover space. $\endgroup$
    – user856
    Jan 17, 2012 at 10:26
  • $\begingroup$ thanks for the correction, will correct it soon. So how do i go about finding the optimal solution for this? $\endgroup$ Jan 17, 2012 at 11:01
  • $\begingroup$ If I knew, I would have posted an answer. But someone else has... $\endgroup$
    – user856
    Jan 17, 2012 at 11:15

1 Answer 1


I don't think there's any "formula" for this and as far as I remember the problem is conjectured to be NP-hard, but not proven to be. For a heuristic that finds very good solutions (conjectured by the authors to be optimal), see this.

  • $\begingroup$ what about finding how many could fit in x and how many could fit in y then we have how many could fit totally by multiplying the results $\endgroup$
    – albanx
    May 12, 2015 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .