0

I have 6 variables whose sum is fixed. How can I get all possible combinations?

for m1 in range(10):
    for m2 in range(10-m1):
        for m3 in range(10-m1-m2):
            for m4 in range(10-m1-m2-m3):
                for m5 in range(10-m1-m2-m3-m4):
                    m6=10-m1-m2-m3-m4-m5
                    print([m1,m2,m3,m4,m5,m6])

  • 1
    That's not a duplicate; the word "combinations" in this question does not mean what "combination" means in the other question. This question is looking to iterate over integer partitions. – kaya3 Nov 16 '19 at 02:47
  • 1
    Possible duplicate of [Python Integer Partitioning with given k partitions](https://stackoverflow.com/questions/18503096/python-integer-partitioning-with-given-k-partitions) – kaya3 Nov 16 '19 at 02:48
  • Does this answer your question? [Elegant Python code for Integer Partitioning](https://stackoverflow.com/questions/10035752/elegant-python-code-for-integer-partitioning) – ggorlen Nov 16 '19 at 02:55
  • What is the code supposed to do? Your post isn’t entirely clear. – AMC Nov 16 '19 at 03:21

0 Answers0