Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.25 KB

holiday_viii-duty_free.md

File metadata and controls

30 lines (23 loc) · 1.25 KB

Description

The purpose of this kata is to work out just how many bottles of duty free whiskey you would have to buy such that the savings over the normal high street price would effectively cover the cost of your holiday.

You will be given the high street price (normPrice, in £ (Pounds)), the duty free discount (discount, in percent) and the cost of the holiday (in £).

For example, if a bottle costs £10 normally and the duty free discount is 10%, you would save £1 per bottle. If your holiday will cost £500, you would have to purchase 500 bottles to save £500, so the answer you return should be 500.

Another example: if a bottle costs £12 normally and the duty free discount is 50%, you would save £6 per bottle. If your holiday will cost £1000, you would have to purchase 166.66 bottles to save £1000, so your answer should be 166 bottles.

All inputs will be integers. Please return an integer. Round down.

My Solution

def duty_free(price, discount, holiday_cost)
  (holiday_cost / (discount.to_f / 100 * price)).floor
end

Better/Alternative solution from Codewars

def duty_free(price, discount, cost)
  100 * cost / price / discount
end