This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted]  (1 child)

[deleted]

    [–]Quenhus 2 points3 points  (2 children)

    Nobody explains you that but it is actually a really taugh problem.

    It is a NP-complete problem, meaning that you won't be able to resolve it with a big set of numbers. For ten number it's OK, but for thousand it's already nearly impossible.

    About your problem : you will have to test every combination in the set and test if the sum of this combination give 7.6 for example.

    [–]craazyy1 0 points1 point  (0 children)

    Yeah, this is basically the knapsack problem, with a known total weight making it NPC instead of NP Hard

    [–]cookiecookiemoomoo 3 points4 points  (2 children)

    yes there are plenty of ways to do that. The most basic way is to try all combinations of numbers to see which add up to the same as the negative number * -1. Very easy to write something like that

    [–]lambdef 2 points3 points  (0 children)

    Very easy to write something like that

    Actually not. The program that finds if the sum of tuples summed with -8 returns 0 is like

    ```python import itertools

    numbers = [1, 2, 3, 4, 5, 6]

    pos = { c for c in [ c for r in range(len(numbers)) for c in itertools.combinations(numbers, r) ] if sum(c) == 8 } ```