Python Forum
a solution to the Subset Sum Problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a solution to the Subset Sum Problem
#11
(Jan-25-2018, 06:27 AM)Mekire Wrote: Occam's Typo. He meant to write -13.

twice? in the original set, and in the solution set right after it?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#12
My code has (-3) not 3. It also has (13). Is that not visible in your displays?
Reply
#13
Regardless of what you have, -3 and 13 doesn't give a sum of 0. On this point I agree with Skape.
Reply
#14
@league55: what 2-set do you mean that has a sum of 0?

Output:
>>> sum({-3,13})==0 False >>>

Output:
>>> s {0, 2, 5, 7, 13, -3} >>> [ (p,q) for p in s for q in s if p!=q and sum({p,q})==0 ] [] >>>
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#15
Oh, I see my mistake. The sum is 10!

Thanks everyone for being patient. I'll edit the original post to add a note.
Reply
#16
just do it in a modulo 10 world. problem solved.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#17
I am wondering, how would you modify the above program so that it only outputs solutions of fixed size k (if they exist)?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020