lets say i have a list:
L = [1,2,3,4,5,6,7,8,9]
x could be anything, but it wont ever be longer than len(L) - 1.. just for what im asking, im setting it to 3
x = 3
value could also be anything, but not exceeding sum(L)
value = 8
What i am trying to figure out is what combinations of items in the list are equal to value, but the length of the combonation cannot exceed x and you cannot use the same item twice.
the anwsers i would want returned are (but not limited to):
[8], [1,7], [2,6], [3,5], [4,4], [1,2,5], [1,3,4], [1,4,3]
You wouldn't return combination of 4 list items because that would exceed x.
Just fyi, this is not homework lol. This is a personal project im working on, and im just stumped.
I wish i had some broken code to post, but i can't even get that far... im not sure how to tackle this since the value of x can be different... if i had to find a static number of list items whos value = 8, i could do that easily... but im lost with this.
My best attempt used L[a:b] changing the values of b and a as b - a approached x and y <= len(L) ... it gave me results, but only if the list items were next to eachother. (8 would not work, but 9 will give you some returns)
Thanks alot for reading the wall of text, and I apreciate any and all anwsers!