Newsgroups: comp.lang.ruby
From: horndud...@gmail.com
Date: 15 Jan 2006 21:31:05 -0800
Local: Mon, Jan 16 2006 12:31 am
Subject: [QUIZ][SOLUTION] Packing (#62)
Here's my solution. I keep track of the positions of the boxes in each
truckbed and generate the ascii only when it is printed. I was trying to be fancy with the insertion points, but it became too difficult to maintain so I just added every point and removed those covered by and surrounding a box during insertion. I sort the boxes by size to put the biggest ones in first. I'm fairly happy with my solution. Thanks for the quiz! -----Horndude77 class TruckBed #This list maintains where it is possible to add boxes def insert(box) #Stable sort: keep relative order #See if box fits at pos >= curr_box_min[0] && box_min[1] <= curr_box_max[1] && box_max[1] >= curr_box_min[1] end true end def to_s class String truck_bed_dims = ARGF.gets.to_dims truck_beds = [TruckBed.new(*truck_bed_dims)] while boxes.size > 0 puts You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||