views:

857

answers:

4

Hi all,

I have big square. And I would like to split this square into small squares. I need all possible combinations. I know that there are infinity count of combinations but I have one limitation. I have fixed size for smallest square.

I can implement it using brute force. But it is too long.

Is any preferable algorithm for this task?

Thanks!

A: 

There are no "infinite" combinations. In fact, the number may be large but is bounded. Moreover, if you need strict squares (width=height, as opposed to just rectangles) there are even less, since you have to divide the original square (of side L) by the same integers on both sides otherwise you'll be getting rectangles as well. If you're working with integers, I would recommend just dividing L by 2, 3, ... M (L/M = minimum inner square length).

Dan
@Dan, surely it could have an infinite number of possibilties, if he doesn't implement a fixed smallest size. He doesn't state that his break down needs to be whole integer sizes, so he could continue to divide down squares of 0.5^2, 0.25^2, 0.125^2 etc if that limitation weren't in place
Eoin Campbell
Reminds me of the scene in "Little Man Tate", when the teacher has the numbers 1-10 up on the board and asks the class how many are divisible by 2. Getting no answers, she turns to her star pupil: "Fred, I know you know which ones." Bored, Fred looks up, sees the list and says, "Um, all of them." That little "um" at the beginning is the best part, as if to ask, "is this even a question?"
Paul McGuire
+1  A: 

My math is a bit fuzzy but if you have a square (n^2), then you have the length of one side (n).

From n you can calculate all the factors for that number, and use them as the sides for the smaller squares...

E.g.

n^2 = 44100
n = 210

Factors of n = x=2,x=3,x=5,x=7, x= ... and so on.

So you smaller squares for each factor are

x=2 : x^2 = 4 : 44100 / 4 = 11025 small squares
x=3 : x^2 = 9 : 44100 / 9 = 4900 small squares
x=5 : x^2 = 25 : 44100 / 25 = 1764 small squares
x=7 : x^2 = 49 : 44100 / 49 = 900 small squares

and so on

Eoin Campbell
+1, but they don't have to be prime factors I imagine, so factors of 210 are 1, 2, 3, 5, 6, 7, 10, argh, why did you have to pick a number with so many factors?
Patrick McDonald
He could also mean sums of squares, e.g. 5^2 = 3^2 + 4^2
Patrick McDonald
@Patrick, yeah i did that one purpose, multiplying up the first couple of prime numbers ;-) For completeness... "1,2,3,5,6,7,10,14,15,21,30,35,42,70,105,210". Regarding the sum of squares... that'd be a pretty big condition to leave out, and would definitely limit his "Infinite" break down. Presumably he has to divide past integer factors into fractional sized squares
Eoin Campbell
+1  A: 

Well this problem only have solution if we made 2 assumptions (otherwise there is infine combinations)

1) the smalest square has a fixed size
2) the way to cut the big square is also fixed, as if you put the square into a grid which lines are separated by the size of the small square.

There is also an third assumption that would make the problem a bit easier

3) The big square has side K-times bigger than the small square. With K being an integer.

If both assumptions are true we can proceed:

Find the number of N (N beign integer) smallest squares: squares with size N*small-size

 if ((big-size % N*small-size)==0)
    Number += (big-size / N*small-size)^2
 else
    Number += ((big-size / N*small-size)^2) * (big-size % N*small-size)

The * (big-size % N*small-size) in the else condition is there becouse if the bigsquare isn't divided by N, when "griding" the big square with gid-width of N, we will have an "fraction part" left. This way we can start dividing again (griding again) but with an offset of 1, 2 or N small steps. The amount of steps is (big-size % N*small-size).

Again, these steps only hold true if the 3 assumptions were took.

RMAAlmeida
I can use grid. Cell of this grid will be smallest square. But I need not only count of possible squares. I need squares with all info e.g. for big square with size=4 and with smallest size=2 one of the possible combination is the following :square1= x=0, y=0, size=2square2= x=2, y=0, size=2square3= x=0, y=2, size=2square4= x=2, y=2, size=2How to get all combinations without brute force?
A: 

I can use grid. Cell of this grid will be smallest square. But I need not only count of possible squares. I need squares with all info e.g. for big square with size=4 and with smallest size=2 one of the possible combination is the following :

  1. square1= x=0, y=0, size=2
  2. square2= x=2, y=0, size=2
  3. square3= x=0, y=2, size=2
  4. square4= x=2, y=2, size=2

How to get all combinations without brute force?

Just to be clear: do you want tilings with combinations of sizes too ? For example there's a variant of the above where 4 is replaced by 4,5,6,7 all with size 1 at (2,2),(2,3),(3,2),(3,3).
timday
Yes. Tiles could have different sizes.