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 decreasing_first_fit(elements, max_bin_size) | |
bins = [elements.first.class.new] | |
elements.sort_by{|e| e.size}.reverse.each do |e| | |
found_place = false | |
bins.each_with_index do |bin, i| | |
if bin.size + e.size <= max_bin_size | |
bins[i] += e | |
found_place = true | |
#puts "found place for #{e} in bin #{i}" | |
break |