Files

- main.py

main.py

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

```
# Solves 13th "Play With Your Math Problem
# Link --> http://www.playwithyourmath.com/
# How many pairs of these numbers (see list below) add to a multiple of 13
# Allows me to use 'combinations()' below which automatically looks at every possible pair
# assuming no repeats, i.e. 65+65=130 which is a multiple of 13.
import itertools
# This is the list of numbers given
given_addends = [11,29,65,26,9,93,62,79,24,2,54,15,106,4,115,37,76]
# This is the number you are looking for multiples of
given_factor = 13
# This is used to count how many pairs have been found that work
solution_counter = 0
# 'for' executes a set of commands (the indented stuff) for very element in list
# itertools.combinations() makes a list of all of the combos
# if you want to consider 65+65 or 11+11 etc., replace "combinations" with:
# combinations_with_replacement
for combo in itertools.combinations(given_addends, 2): #Looks at every combination
# Checks if a combo's sum is divisible by 13 using mod(13) noted by the %
# (combo[0] + combo[1]) is just the notation for getting the two numbers from the list
# that the for 'for' command generates
if (combo[0] + combo[1]) % given_factor == 0:
# If the combo works this prints it
print combo
# If the combo works, this increases the count of pairs that work
solution_counter += 1
print 'There are', solution_counter, 'combinations with a sum that is a multiple of', given_factor, '.'
```