Hold the phone: quick test shows there's something wrong with this. Give me a couple of minutes...

Danny

----- Original Message ----- From: "Danny Kodicek" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Monday, May 08, 2006 3:37 PM
Subject: Re: [Flashcoders] Fitting squares into an area


This seemed like a really simple problem when I first looked at it, but
actually I think it's pretty subtle. I don't know about a standard
algorithm, but here's my take:

I think your best option, as Bernard said, is a brute force technique.
Here's the algorithm I'd use (probably could be optimised a bit):

function squareWidth (x, y, N) {
   var p = 1
   var q = 1
   var w1 = x
   var w2 = y
   var nextW1 = x/2
   var nextW2 = y/2
   while (true) {
       var numSquares = p*q
       var currWidth = Math.min(w1,w2)
       if (numSquares >= N) {return currWidth}
       if (nextW1>nextW2) {
           p++
           w1 = nextW1
           nextW1 = x/(p+1)
       } else {
           q++
           w2 = nextW2
           nextW2 = x/(p+2)
       }
   }
}

Best
Danny


----- Original Message ----- From: "Mike Mountain" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Monday, May 08, 2006 2:02 PM
Subject: RE: [Flashcoders] Fitting squares into an area


All my squares need to be the same size - so for example what's the best way
of laying out 'n' equal squares in an areas x,y so the squares are as big as
they can be. There must be an algo for this kind of thing.

M

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Of Kerem Gülensoy
Sent: 08 May 2006 13:59
To: 'Flashcoders mailing list'
Subject: AW: [Flashcoders] Fitting squares into an area

you could divide the area, divide one half again, divide the
other half, and so on...n-times...

cheers | kerem

-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Im Auftrag
von Mike Mountain
Gesendet: Montag, 8. Mai 2006 14:51
An: Flashcoders mailing list
Betreff: [Flashcoders] Fitting squares into an area

Anyone got any script to cover the following problem:
Given an area (x,y)  what's the best way of filling it with
'n' squares?
Cheers
M
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to