class Array
def shuzzle
providers = Provider.find(:all).map {|it| it.id}
set = []
providers.each do |p|
grp = []
self.each {|it| grp << it if it.provider_id == p}
set << grp
end
result = []
set.each {|it| result.push(it.pop) if it.any?} while set.flatten.any?
return result
end
end

Products.find(:all).shuzzle