-6

I want to know the possible combinations in code/algorithm for three numbers with an increment of 5 and a total of 100. See examples below.

5 10 85

5 15 80

5 20 75

.

.

10 15 75

Thank you.

  • 2
    Welcome to SO! We're glad to help you, but we won't write code for you. – georg Mar 25 '13 at 09:18
  • I think you need the same amount of time to write the numbers by hand and to program the algorithm. As thg435 is right we won't write code consider the first option. – wagnerpeer Mar 25 '13 at 09:40
  • 1
    What you're trying to find is the *partitions of 100 of length 3 and in units of 5*. Read up on [wikipedia](https://en.wikipedia.org/wiki/Partition_(number_theory)) and see [this article](http://wordaligned.org/articles/partitioning-with-python) for some code examples. You'll find [several](http://stackoverflow.com/questions/10035752/elegant-python-code-for-integer-partitioning) [questions](http://stackoverflow.com/questions/7802160/number-of-ways-to-partition-a-number-in-python) on StackOverflow about this too. – Lauritz V. Thaulow Mar 25 '13 at 10:04

1 Answers1

2

Get all possible combinations and check if the sum is 100.

In code it looks like this:

import itertools
base = range(5, 100, 5)
combis = itertools.combinations(base, 3)
for values in combis:
    if sum(values) == 100:
        print(values)

This gives you all results. You should have no problems to count them.

If you want to learn try it without itertools.

Matthias
  • 12,873
  • 6
  • 42
  • 48