Python Forum

Full Version: find the sum of a series of values that equal a number
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, i'm completely new of Python. I know that there would be a way to determine, form a series of values, which values are corresponding to a certain another value.
Example: i have a list of values, 110,230,340,200,500,450 and a another value, for example 840. I want to find for which values, of the first series, theri sum is equal to 840. Is it possibile ?
Thanks for the help.
This is a well-known problem in theoretical computer science, the subset sum problem, which is known to be NP-hard, which means that no fast algorithm will solve the problem when the size of the input data is large (eg the length of the list).

I have found one package (untested) in the Python Package Index subsetsum but it relies on C++ code. You could perhaps check this package.

Apart from this, a search engine finds pure Python implementations such as this one.