6 kyu

T.T.T.41: The maximum profit

75 of 92myjinxin2015

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!!!
Puzzles
Games

Similar Kata:

Stats:

CreatedAug 16, 2016
PublishedAug 16, 2016
Warriors Trained233
Total Skips12
Total Code Submissions214
Total Times Completed92
JavaScript Completions75
Python Completions22
Total Stars2
% of votes with a positive feedback rating97% of 31
Total "Very Satisfied" Votes29
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • saudiGuy Avatar
Ad