T.T.T.41: The maximum profit
Description:
Story
John is a businessman, pursuit of the biggest profit is his life fun. He runs a furniture storethe, dealing with different customers every day.
One day, he received an order. A customer ordered 80 tables, each table price is $100. "If you are willing to lower the price, for every 1 dollars, I will buy 4 extra tables." Customer said.
We know the cost of a table is $75. Please think for John, what kind of price can get the maximum profit?
For this case, the answer should be 97.
Thinking process:
if price=100 profit = (100-75)*80 = 2000
if price=99 profit = (99-75)*84 = 2016
if price=98 profit = (98-75)*88 = 2024
if price=97 profit = (97-75)*92 = 2024
if price=96 profit = (96-75)*96 = 2016
if price=95 profit = (95-75)*100 = 2000
if price=94 profit = (94-75)*104 = 1976
.....
.....
We can see that when the price is 97 or 98 , Jhon can get the maximum profit. Of course, the choice of 97 can make customer more happy, so the 97 is the best answer.
Task
Complete function maximumProfit()
that accepts four arguments:
price
: The current sales price.
cost
: The actual cost of the table.
quantity
: Current purchase quantity.
extra
: Customer extra purchase quantity(the price reduced by $1).
You should return a number which is the best price. It can get the maximum profit also can make customer more happy.
Examples
maximumProfit(100,75,80,4) === 97
maximumProfit(100,70,80,4) === 95
maximumProfit(100,70,80,10) === 89
maximumProfit(1000,70,80,10) === 539 //Profiteer!!!
maximumProfit(100,75,80,100) === 88 //Crazy customer...
maximumProfit(100,75,80,1) === 100 //To maintain the original price is the best choice
maximumProfit(100000,70,80,10) === 50039 //Big profiteer!!!
Similar Kata:
Stats:
Created | Aug 16, 2016 |
Published | Aug 16, 2016 |
Warriors Trained | 233 |
Total Skips | 12 |
Total Code Submissions | 214 |
Total Times Completed | 92 |
JavaScript Completions | 75 |
Python Completions | 22 |
Total Stars | 2 |
% of votes with a positive feedback rating | 97% of 31 |
Total "Very Satisfied" Votes | 29 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |