aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-11-03 18:38:51 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-11-03 18:38:51 +0000
commit9cfe9430aee48716f1e4f6da28f5a4763118a373 (patch)
tree3f0b22196f1be7f3495bdf6971bd29ecdd679fbf /challenge-113/paulo-custodio/python/ch-1.py
parent3138afab1ae0e0cd8d7b9c0a829e4f2f1bba91a5 (diff)
downloadperlweeklychallenge-club-9cfe9430aee48716f1e4f6da28f5a4763118a373.tar.gz
perlweeklychallenge-club-9cfe9430aee48716f1e4f6da28f5a4763118a373.tar.bz2
perlweeklychallenge-club-9cfe9430aee48716f1e4f6da28f5a4763118a373.zip
Add Python solution to challenge 113
Diffstat (limited to 'challenge-113/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-113/paulo-custodio/python/ch-1.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-113/paulo-custodio/python/ch-1.py b/challenge-113/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..e544a5ccd8
--- /dev/null
+++ b/challenge-113/paulo-custodio/python/ch-1.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+# Challenge 113
+#
+# TASK #1 - Represent Integer
+# Submitted by: Mohammad S Anwar
+# You are given a positive integer $N and a digit $D.
+#
+# Write a script to check if $N can be represented as a sum of positive
+# integers having $D at least once. If check passes print 1 otherwise 0.
+#
+# Example
+# Input: $N = 25, $D = 7
+# Output: 0 as there are 2 numbers between 1 and 25 having the digit 7
+# i.e. 7 and 17. If we add up both we don't get 25.
+#
+# Input: $N = 24, $D = 7
+# Output: 1
+
+import sys
+import re
+
+def represent(n, d):
+ sum = 0
+ for i in range(n+1):
+ if re.search(str(d), str(i)):
+ sum += i
+ return sum==n
+
+if represent(int(sys.argv[1]), int(sys.argv[2])):
+ print(1)
+else:
+ print(0)