aboutsummaryrefslogtreecommitdiff
path: root/challenge-065/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-09-25 14:53:58 -0400
committerDave Jacoby <jacoby.david@gmail.com>2024-09-25 14:53:58 -0400
commit351a05d8cf592f39d6807167875515c68cf485eb (patch)
tree1e2f740dc47fe5e61eb710cab9dc357b0059fc0e /challenge-065/paulo-custodio/python/ch-1.py
parentf86f5e2fec16020c1d86f9028fb0f61cfeac106e (diff)
parent4a2fee41a38b28f1e17b26768caf000185fa5350 (diff)
downloadperlweeklychallenge-club-351a05d8cf592f39d6807167875515c68cf485eb.tar.gz
perlweeklychallenge-club-351a05d8cf592f39d6807167875515c68cf485eb.tar.bz2
perlweeklychallenge-club-351a05d8cf592f39d6807167875515c68cf485eb.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-065/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-065/paulo-custodio/python/ch-1.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-065/paulo-custodio/python/ch-1.py b/challenge-065/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..344143f905
--- /dev/null
+++ b/challenge-065/paulo-custodio/python/ch-1.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+# Challenge 065
+#
+# TASK #1 > Digits Sum
+# Submitted by: Mohammad S Anwar
+# Reviewed by: Ryan Thompson
+#
+# You are given two positive numbers $N and $S.
+#
+# Write a script to list all positive numbers having exactly $N digits where sum
+# of all digits equals to $S.
+#
+# Example
+# Input:
+# $N = 2
+# $S = 4
+#
+# Output:
+# 13, 22, 31, 40
+
+import sys
+from itertools import product
+
+def digits_sum(N, S):
+ out = []
+ for n in range(10**(N-1), 10**N):
+ if sum(int(d) for d in str(n)) == S:
+ out.append(n)
+ return out
+
+N, S = map(int, sys.argv[1:])
+out = digits_sum(N, S)
+print(", ".join(map(str, out)))