although I encountered this problem while coding, I think it is more math than coding.
The task is simple: I have three baskets of size $B_1$, $B_2$, and $B_3$ (every number is an integer here) and $A <= B_1 + B_2 + B_3$ units to distribute among those baskets. Basket 1 can hold between 0 and $B_1$ units, and so on. This gives me a list of possible combinations to distribute the A units, and this list is sorted (I can choose the sorting algorithm as I want to, and am currently working with the lexicographical order, i.e. the first is $(0,0,A)$, the second $(0,1,A-1)$, and so on).
The question: Having an element $(A_1,A_2,A_3)$ with $A_1 + A_2 + A_3 = A$ and knowing $B_1$, $B_2$, and $B_3$, is there a formula that tells me the index of $(A_1,A_2,A_3)$ in the list of possible combinations?
Example: If $(B_1,B_2,B_3) = (10,30,60)$ and $A = 61$, there are 340 combinations, ${(0,1,61),(0,2,60),...,(10,30,51)}$. The index of $(5,20,36)$ is then $174$.
Any ideas? As it is part of a larger code, I could always back up the formula with a mundane index search via a loop, so a formula that "only" works in 99% of the times would already be helpful. I found something that works in my example for every $A$ but those between 60 and 70, which is not enough to speed up my code.
Thanks a lot in advance :-)
PS: In my coding exercise, I can reduce the number of combinations significantly, but leaves the set of combinations without any foreseeable structure. Unfortunately, the index search still takes very long. My alternative would be to just not reduce them, work with the large set of combinations but utilize the structure of this set. However, I would need a short/fast formula for this then.