aboutsummaryrefslogtreecommitdiff
path: root/challenge-075/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-25 09:29:21 +0100
committerGitHub <noreply@github.com>2024-09-25 09:29:21 +0100
commit261da1d2c54ab8faab88537076b4248d5abd00f7 (patch)
treec60a0327997c7d9759f275323ae120d735726784 /challenge-075/paulo-custodio/python/ch-1.py
parent9e56f497ae79225e5a6e041a963741885335d0d0 (diff)
parent206c2fce8db1de9b7f82f04a3276005a284b3c40 (diff)
downloadperlweeklychallenge-club-261da1d2c54ab8faab88537076b4248d5abd00f7.tar.gz
perlweeklychallenge-club-261da1d2c54ab8faab88537076b4248d5abd00f7.tar.bz2
perlweeklychallenge-club-261da1d2c54ab8faab88537076b4248d5abd00f7.zip
Merge pull request #10906 from pauloscustodio/master
Add Python solutions
Diffstat (limited to 'challenge-075/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-075/paulo-custodio/python/ch-1.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/challenge-075/paulo-custodio/python/ch-1.py b/challenge-075/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..b86bde2230
--- /dev/null
+++ b/challenge-075/paulo-custodio/python/ch-1.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+# Challenge 075
+#
+# TASK #1 > Coins Sum
+# Submitted by: Mohammad S Anwar
+# You are given a set of coins @C, assuming you have infinite amount of each
+# coin in the set.
+#
+# Write a script to find how many ways you make sum $S using the coins from
+# the set @C.
+#
+# Example:
+# Input:
+# @C = (1, 2, 4)
+# $S = 6
+#
+# Output: 6
+# There are 6 possible ways to make sum 6.
+# a) (1, 1, 1, 1, 1, 1)
+# b) (1, 1, 1, 1, 2)
+# c) (1, 1, 2, 2)
+# d) (1, 1, 4)
+# e) (2, 2, 2)
+# f) (2, 4)
+
+import sys
+
+def show_coins(want, coins):
+ def show_coins1(want, have, coins, seen):
+ sum_have = sum(have)
+ if sum_have > want:
+ pass # busted sum
+ elif sum_have == want:
+ out = ", ".join([str(x) for x in sorted(have)])
+ if not out in seen:
+ seen[out] = 1
+ print(out)
+ else:
+ for coin in coins:
+ show_coins1(want, have+[coin], coins, seen)
+
+ show_coins1(want, [], coins, {})
+
+S = int(sys.argv[1])
+C = [int(x) for x in sys.argv[2:]]
+show_coins(S, C)