aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/sgreen/python/ch-2.py
blob: 6ea25dabacb56120e5999aba4dfc558e418c105b (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
30
#!/usr/bin/env python3

import sys


def making_change(remaining: int, last_coin: int | None = None) -> int:
    combinations = 0

    for coin in [1, 5, 10, 25, 50]:
        if last_coin and last_coin < coin:
            # We can't use a larger coin that the last one
            continue
        if coin == remaining:
            # We have found a solution
            combinations += 1
        if coin < remaining:
            # Call the function again, taking away the value of the coin
            combinations += making_change(remaining-coin, coin)

    # This value is returned upstream as we go
    return combinations


def main():
    result = making_change(int(sys.argv[1]))
    print(result)


if __name__ == '__main__':
    main()