Skip to content

Instantly share code, notes, and snippets.

@bmaland
Created September 22, 2008 19:27
Show Gist options
  • Save bmaland/12112 to your computer and use it in GitHub Desktop.
Save bmaland/12112 to your computer and use it in GitHub Desktop.
def max_discount(prices)
prices = prices.sort.reverse
discount = 0
while prices != []
discount += prices[0..2].min
prices = prices[3..-1]
end
discount
end
gets.to_i.times do
gets
puts max_discount gets.split(" ").map(&:to_i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment