I am currently working on a project for myself but I got stuck during the exercise.
Inside the project, there is a task where we need to distribute a certain value to different variables until zero.
For example, I have 3000 units rice and want to sell it for different prices.
Best price 4$ then 3$, 2$ etc.
The 4$ market will sometimes by more sometimes less but has priority, the rest gets sold for 3$ first and then for 2$ until nothing is left.
I am trying to find a nice way to put this in an algorithm for hours now but can't find a nice way.
The price does not get reduced, I will always prefer the 4$ option then 3$ and afterwards 2$.
Only my amount of units will change and the demand each market has.
I always want to give the full demand of units to the first market and check if there is still something left for the second, third...
The algorithm should show how much demand was fulfilled and how much is left.