Lets say we have an initial fortune of 10$ and we want to make money by buying and selling potatoes and in a magical way we know the prices($) per kg per year of each potato spice. What is the best algorithm to find the final maximum fortune or a local maximum?
!! If you have a fortune 15$ and you sell some kg in a year and earn lets say 4$ more you cant buy something that costs you 19$ at the same year, they are independent so you should have the money to buy something before selling something else in the same year !!
e.g
starting fortune : 10$
Prices($) per kg of potato spice per year:
Potato Spice 1 price($) per kg:
[5, 8, 7, 10, 12, 11, 14, 11, 10]Potato Spice 2 price($) per kg:
[8, 8, 4, 5, 7, 15, 10, 12, 10]Potato Spice 3 price($) per kg:
[4, 7, 5, 6, 10, 9, 11, 15, 11]
What will be a good solution for that?
A simple local maximum can be made by the following path:
- 1st Year:
[Buy 1 kg (5$) from first spice]
[Buy 1.25 kg (5$) from third spice]- 2nd Year:
[Sell 1kg (8$) from first spice]- 3rd Year:
[Buy 2 kg (8$) from second spice]- 4th Year: nothing
- 5th Year: nothing
- 6th Year: nothing
- 7th Year: nothing
- 8th Year:
[Sell 1.25 kg (-15x1.25=18.75 $) from third spice]
[Sell 2 kg (12x2=24 $) from second spice]- 9th Year
nothingFortune 42.75$ (this was an example, for sure not the maximum fortune)