aboutsummaryrefslogtreecommitdiff
path: root/challenge-143/paulo-custodio/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-12-13 16:28:00 +0000
committerGitHub <noreply@github.com>2021-12-13 16:28:00 +0000
commit3f102edbf082ea633a4f832969809eb693cf738a (patch)
tree8f094295e5420d4ba21a45198396b649e1aebf93 /challenge-143/paulo-custodio/python/ch-2.py
parent495113ce801fcfa3b0a8cdd8d276ae2f8c02612e (diff)
parentf0cb20786217f904bc70da6ccf9521ad50d95f31 (diff)
downloadperlweeklychallenge-club-3f102edbf082ea633a4f832969809eb693cf738a.tar.gz
perlweeklychallenge-club-3f102edbf082ea633a4f832969809eb693cf738a.tar.bz2
perlweeklychallenge-club-3f102edbf082ea633a4f832969809eb693cf738a.zip
Merge pull request #5369 from pauloscustodio/devel
Add Perl and Python solution to challenge 143
Diffstat (limited to 'challenge-143/paulo-custodio/python/ch-2.py')
-rw-r--r--challenge-143/paulo-custodio/python/ch-2.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-143/paulo-custodio/python/ch-2.py b/challenge-143/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..3d1976d3f0
--- /dev/null
+++ b/challenge-143/paulo-custodio/python/ch-2.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python3
+
+# TASK #2 > Stealthy Number
+# Submitted by: Mohammad S Anwar
+# You are given a positive number, $n.
+#
+# Write a script to find out if the given number is Stealthy Number.
+#
+# A positive integer N is stealthy, if there exist positive integers a, b, c, d
+# such that a * b = c * d = N and a + b = c + d + 1.
+#
+# Example 1
+# Input: $n = 36
+# Output: 1
+#
+# Since 36 = 4 (a) * 9 (b) = 6 (c) * 6 (d) and 4 (a) + 9 (b) = 6 (c) + 6 (d) + 1.
+# Example 2
+# Input: $n = 12
+# Output: 1
+#
+# Since 2 * 6 = 3 * 4 and 2 + 6 = 3 + 4 + 1
+# Example 3
+# Input: $n = 6
+# Output: 0
+#
+# Since 2 * 3 = 1 * 6 but 2 + 3 != 1 + 6 + 1
+
+import sys
+
+def is_stealthy(n):
+ for a in range(1, n+1):
+ if n%a==0:
+ b = n/a # a*b=n
+ for c in range(1, n+1):
+ if n%c==0:
+ d = n/c # c*d=n
+ if a+b==c+d+1:
+ return 1
+ return 0
+
+n = int(sys.argv[1])
+print(is_stealthy(n))