1

Yes I did see the questions similar to this already posted here (notably this one).

But. Am i crazy, or can the size of the square also be a non-integer? For example, in a 2x3 rectangle, one solution is squares that are .2x.2

How can i create a function to find the number of possible square sizes?

Community
  • 1
  • 1
Ethan
  • 400
  • 3
  • 14
  • 1
    If you allow fractional square sizes (e.g. 0.2 x 0.2), there are an infinite number of possible square sizes, since any square can be divided into four squares. – James McNellis Dec 11 '09 at 23:48
  • That makes sense. So how do i modify the function to find solutions in a certain range, for example? Or closest to a target size? – Ethan Dec 12 '09 at 00:05

1 Answers1

3

Turn it back into an integer problem. Suppose you want the smallest quantum of length to be 0.1, just multiply all dimensions by 10 and you are back to an integer problem. Then at the end, scale it back down.

This general technique is used a lot in embedded software where you don't want to play with floating point too much, but need to deal in fractions, such as fractions of a second.