aboutsummaryrefslogtreecommitdiff
path: root/challenge-075/lubos-kolouch/python/ch-1.py
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2020-08-31 17:55:06 +0800
committer冯昶 <seaker@qq.com>2020-08-31 17:55:06 +0800
commitfcd02aeeda87c122867e4173ad34ac8e4c752aa2 (patch)
tree2c91adbb6c158528d06c1294e066bd34f4c9eae3 /challenge-075/lubos-kolouch/python/ch-1.py
parent4a2d3428b9c5d6fbbfabafe0d9303b45bdb59295 (diff)
parent87c6f1e47af81cce9da9dde6e73ca9de5bd77367 (diff)
downloadperlweeklychallenge-club-fcd02aeeda87c122867e4173ad34ac8e4c752aa2.tar.gz
perlweeklychallenge-club-fcd02aeeda87c122867e4173ad34ac8e4c752aa2.tar.bz2
perlweeklychallenge-club-fcd02aeeda87c122867e4173ad34ac8e4c752aa2.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-075/lubos-kolouch/python/ch-1.py')
-rw-r--r--challenge-075/lubos-kolouch/python/ch-1.py21
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