- I have a list of
Nitems - The price of the 1st item in the list is
valueA - I want the price to gradually increase from one item to the next one in the list.
- If I sell all N items, I want my total earnings to be
T. - I'm looking for the price each item should have (Currently I only know the price of the 1st one:
valueA).
In other words, the following must be true:
(valueA + valueB + valueC + .... + valueN) === T
and:
valueA < valueB < valueC < .... < valueN
I'm looking for a formula that will return these values [valueA, valueB, valueC, ....valueN]
To give you a more or less simple example:
If valueA is 1, N is 7 and targetSum is 25, then one valid result could be:
[1, 2, 2.5, 3.5, 4, 5.5, 6.5]
or:
[1, 2, 2.5, 3.5, 4, 5, 7]
and many other combinations.. but I'm looking for the single most linear (in terms of increments) solution if that makes sense.
Is what I'm looking for impossible due to the Subset sum problem?
If it's actually possible, given that I am not a mathematician and I don't understand mathematical formulas, I would appreciate it if you could also include a more "verbose" answer as in (random example):
(add/divide/multiple currently known values) and their result X is your 2nd price
now knowing X move on to the 3rd price and repeat the above etc...
targetSumin the end: https://jsfiddle.net/f0xj69na/1 – Sprout Coder May 15 '22 at 01:11