Created
January 28, 2009 17:58
-
-
Save danielharan/54103 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
# We order a LOT of pizza at GiraffeSoft | |
# (there are 14 empty boxes on the table, and 3 more on the way) | |
# So, what's the cheapest way to buy them? | |
# | |
# in irb, | |
# include PizzaOptimizer | |
# compare([[9,11],[12,14],[14, 21]]) | |
# 9" @ 11 => 0.270170428088094 | |
# 12" @ 14 => 0.25788995408409 | |
# 14" @ 21 => 0.331572798108115 | |
module PizzaOptimizer | |
def cost_per_square_inch(pizza_diameter, cost) | |
cost.to_f / circle_area(pizza_diameter / 2) | |
end | |
def circle_area(radius) | |
Math::PI * (radius ** 2) | |
end | |
def compare(pizzas) | |
pizzas.each do |diameter, price| | |
puts "#{diameter}\" @ #{price} => #{cost_per_square_inch(diameter, price)}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment