0
  1. I have a list of N items
  2. The price of the 1st item in the list is valueA
  3. I want the price to gradually increase from one item to the next one in the list.
  4. If I sell all N items, I want my total earnings to be T.
  5. 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...

1 Answers1

1

Suppose that :

  • $x_1 + x_2 + \cdots + x_n = T$
  • $0 < x_1 < T$
  • There exists $k > 0$ such that
    for all $m \in \{1,2,\cdots,n-1\}, ~x_{m+1} - x_m = k.$

If this is possible, then this will automatically satisfy the desired constraints.

So, it is simply a matter of solving for $k$.

The only way that this is possible is if $(n \times x_1) < T.$
So, without loss of generality, assume that this is true.

You have that :
$x_2 = x_1 + k.$
$x_3 = x_2 + k = x_1 + 2k.$
$x_4 = x_3 + k = x_1 + 3k.$
$\cdots$
$x_{n} = x_n + k = x_1 + (n-1)k.$

Therefore

$$T = x_1 + \cdots + x_n = (n \times x_1) + [k + 2k + \cdots + (n-1)k]$$

$$= (n \times x_1) + \sum_{i=1}^{n-1} ik$$

$$= (n \times x_1) + \left(k \times \frac{(n-1)(n)}{2}\right).$$

The above equality will be satisfied if and only if $k$ is chosen so that

$$T - nx_1 = \frac{kn(n-1)}{2} \iff \frac{2(T - nx_1)}{n(n-1)} = k.$$

user2661923
  • 35,619
  • 3
  • 17
  • 39