Created
November 7, 2012 06:33
-
-
Save pumpchaser/4029859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute_packages | |
packages = Packages.all # or however you get all your package | |
items = get_items #array of items | |
packages.each do |old_package| | |
items.each do |item| | |
old_package << item if old_package #if it has space (true), add the item | |
items.delete item if old_package #delete item, not sure if you can make this call inside of an iteration block | |
break if !old_package | |
end | |
end | |
while items | |
new_package = Package.new | |
items.each do |item| | |
new_package << item if new_package | |
items.delete item if new_package | |
break if !new_package | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment