Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Rectangle packing...

by Necos (Friar)
on Apr 23, 2002 at 15:55 UTC ( [id://161347]=note: print w/replies, xml ) Need Help??


in reply to Rectangle packing...

This is an interesting problem. One solution (simplified) is:
$canvas{width} = 8.5; $canvas{height} = 11; foreach(@pictures_to_canvas){ if ( ($canvas{width} > $$_{width}) && ($canvas{height} > $$_{width +}) { $canvas{width} -= $$_{width}; $canvas{height} -= $$_{height}; } #Throw exception here if height or width goes below a min value. } ...
I hope this code makes sense. If you make width and height "properties" of the photos, it's just a matter of dividing the canvas into vertical and horizontal components, iterating through the photos, and throwing an exception when you've gotten too much on the canvas (or at least, that's how I've thought about it).

This would even work with while/until/etc... loops, but I thought the foreach was the simplest.

Hope this helps just a tiny bit.
Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com
perl -e "map{print++$_}split//,Mdbnr;"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://161347]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-23 20:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found