Resizing and fitting a group of rectangles so that they do not leave any space in between each other

In the left part of the picture various sized squares are placed inside a 10 by 10 square. But after this process some space is left out in between them. I want to get rid of this space is possible as shown in picture on the right. It does not matter is the squares are changed into rectangles but they must keep the same area. (17.9 KB)

Duplicate threads are getting to be a bad habit with you, @James_Foley. Please stop that?

Also, how about providing code with your posts without being asked each time? See #3 on this page:

So I cannot ask two different questions about the same project? Those two questions are completely unrelated. In the first one i’m asking How to make a grid in an irregular shape and in this one How to pack squares into a smaller space. I don’t see how are they related. I could ask the question in the same topic but then the topic would have two unrelated questions. It’s also easier for people in the future to go through topics if they are individual questions.

Both threads appear to use exactly the same code and deal with the very same problem. What in the world makes you think that not posting that code is a good idea?

6. Create new topics rather than continuing old ones
It’s usually better to start a fresh question, even if there’s already a discussion that kinda sorta tangentially touches upon the same issue. Please link to that discussion, but start anew.