diff options
| author | Myoungjin JEON <jeongoon@gmail.com> | 2020-08-28 22:54:33 +1000 |
|---|---|---|
| committer | Myoungjin JEON <jeongoon@gmail.com> | 2020-08-28 22:54:33 +1000 |
| commit | 113c25e7c3e065fb32fbcae91cb1c7444db89c1f (patch) | |
| tree | 4926baeb6d4e95e9ceceb13734246154dd570965 /challenge-075/lubos-kolouch/python/ch-1.py | |
| parent | f270b932857463ce2a02308887394ac34a032578 (diff) | |
| parent | 15ac63c0f3554fc95fbeb05fa7504a205ab76142 (diff) | |
| download | perlweeklychallenge-club-113c25e7c3e065fb32fbcae91cb1c7444db89c1f.tar.gz perlweeklychallenge-club-113c25e7c3e065fb32fbcae91cb1c7444db89c1f.tar.bz2 perlweeklychallenge-club-113c25e7c3e065fb32fbcae91cb1c7444db89c1f.zip | |
Merge remote-tracking branch 'upstream/master' into ch-075
Diffstat (limited to 'challenge-075/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-075/lubos-kolouch/python/ch-1.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-075/lubos-kolouch/python/ch-1.py b/challenge-075/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..c706f7f5a0 --- /dev/null +++ b/challenge-075/lubos-kolouch/python/ch-1.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +""" Perl weekly challenge 075 Task 1 - Coins sum """ + + +def count(coins, target_sum): + """ count the ways we can sum coins """ + + ways = [0] * (target_sum + 1) + + ways[0] = 1 + + for value in coins: + for j, _ in enumerate(ways): + if value <= j: + ways[j] += ways[j - value] + + return ways[target_sum] + + +assert count([1, 2, 4], 6) == 6 +assert count([1, 5, 10], 12) == 4 |
