Skip to content

Instantly share code, notes, and snippets.

@dnene
Created October 31, 2011 00:59
Show Gist options
  • Save dnene/1326668 to your computer and use it in GitHub Desktop.
Save dnene/1326668 to your computer and use it in GitHub Desktop.
Generate weight combinations for four pieces totalling 40 pounds (int vals)
wts = tuple((w1,w2,w3,n-(w1+w2+w3)) for w1 in range(1,n) for w2 in range(w1,n - w1) for w3 in range(w2, n-w1-w2) if n-(w1+w2+w3) -w3 >= 0)
print len(wts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment