0

someone owes to my company 16 different invoices for a total amount of 29048,88 $. they paid me this amount in 2 different transfer 1 of 19993,92 $ 2 of 9054,96 $

How can i find the invoices paid in first and second transfer? If you have an idea to solve this just with a simple math equation or with javascript (loop maybe) Thanks

  • 1
    The only possibility is if you know the price of most (all) invoices. Mathematically speaking, you have less equations than unknowns which means there is an infinite number of answers to your question. Let `i_k` be the kth invoice. Your problem can be expressed as follows: `i_0 + i_1 + i_2 + .... + i_15 = 29 048.88`. That's 16 unknowns 1 equation. – AlexG Apr 10 '19 at 18:58
  • in fact i know the amount of each 16 invoices. – Jean-Paul Arnéodo Apr 10 '19 at 19:00
  • anyone has ideas, some help? – Jean-Paul Arnéodo Apr 10 '19 at 21:29
  • Possible duplicate of [Finding all possible combinations of numbers to reach a given sum](https://stackoverflow.com/questions/4632322/finding-all-possible-combinations-of-numbers-to-reach-a-given-sum) – recnac Apr 12 '19 at 04:38

1 Answers1

0

Possible duplicate of this question?

I think this answer solves your problem.

I copy here an python implementation of the solution. But the original answer offers way more choices. The complexity of the algorithm grows quite fast (exponential), so be careful before using it for bigger problems than N=16.

Just enter all your invoices in the list and one of your payment as the second parameter. You will get all combinations of invoices that give the given payment, and the other payment is simply the missing elements of the list. There may be more than one solution.

def subset_sum(numbers, target, partial=[]):
    s = sum(partial)

    # check if the partial sum is equals to target
    if s == target: 
        print("sum(%s)=%s" % (partial, target))
    if s >= target:
        return  # if we reach the number why bother to continue

    for i in range(len(numbers)):
        n = numbers[i]
        remaining = numbers[i+1:]
        subset_sum(remaining, target, partial + [n]) 

subset_sum([31,19,80,48,52,70,10,13,12,54,23,45,34,26,51,23,100],193)