Need some help about Workflow and counter

Here is my data:

userdb

And I’d like to query the system when I click on a button:

How many times can I find the sum 90 (right leg) in the sum 360 (left leg) on the left?

If the system finds only 1 time, then it adds the two sums.


Here I put 90 as an example because it won’t find 1x90 out of 360, it will always try to go up.

If the system finds 2 times only, then it will do 2x90 + 90 again.


Here I put 180 as an example because it won’t find 2x90 out of 360, it will always try to go to 3x90.

If the system finds 3 times only, then it will be 3x90 + 90 again.

On the other two conditions, we always add the sum of the lower leg to make a total.

Without forgetting that once the calculation is done, the system removes the points calculated on each leg.

Example:
On condition 3, the system removes 3x90 points on the left and 90 points on the right, there will remain 90 points on the left and 0 points on the right.

If possible to have a demonstration directly on the workflow, please.
I would especially like to know how to do this on Bubble.

Thanks in advance.

PROBLEM SOLVED, thanks