A
A
ADA M2021-07-02 15:57:45
Mathematics
ADA M, 2021-07-02 15:57:45

Can the algorithm be expressed as a mathematical formula?

Tell me please, I'm dumbing down something wildly. How to express the following logic with a mathematical formula (like sequences x1 ... xn, well, or something else):

1) First case

X1 - Cell A = 500
X2 - Cell B = 500
X3 - Cell C = 500
Z - Payment = 700

In descending order c > b > a, the payment will be distributed and the new amounts will look like this:

Y1 - Cell A = 500
Y2 - Cell B = 300
Y3 - Cell C = 0

2) Second case

X1 - Cell A = 500
X2 - Cell B = 500
X3 - Cell C = 500
Z - Payment = 300

Descending c > b > a the payment will be distributed and the new amounts will look like this:

Y1 - Cell A = 500
Y2 - Cell B = 500
Y3 - Cell C = 200

3) Third case, when the payment is equal to the amount in cell C.

Ie I want to get something like this: y2 = x2 - (z - x3 - ...), y3 = ..., y1 = ...
Is this even possible?) Maybe the systems should help here?
Or without conditions like: if (z > x3) ? 0 : x3 - zcan't do it?
I think the whole problem lies in the impossibility of using negative values ​​...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2021-07-02
@adiletmurzaliev

Use the max.
The value in each cell will be

max(0, (тукущее значение) - max(0, (платеж) - (сумма всех следующих ячеек)))

Since all partial sums will be needed, it makes sense to calculate all these sums in adjacent cells.

G
Griboks, 2021-07-03
@Griboks

Nothing is clear, but very similar to linear programming .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question