aboutsummaryrefslogtreecommitdiff
path: root/challenge-075/abigail/python/ch-1.py
blob: 8b3ce4f9fbf3a5414c543784f7e0f44a290e8fdf (plain)
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
#!/opt/local/bin/python

#
# See ../README.md
#

#
# Run as: python ch-1.py < input-file
#

import fileinput

def possibilities (target, coins, first, last):
    if target == 0:
        return 1

    if target < 0 or first > last:
        return 0

    sum = 0
    for i in range (1 + int (target / coins [first])):
        sum = sum + possibilities (target - i * coins [first],
                                                coins, first + 1, last)

    return sum

for line in fileinput . input ():
    coins = list (map (lambda _: int (_), line . split (" ")))
    print (possibilities (coins [0], coins, 1, len (coins) - 1))