aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-066/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-066/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-066/paulo-custodio/python/ch-1.py43
-rw-r--r--challenge-066/paulo-custodio/python/ch-2.py41
4 files changed, 86 insertions, 2 deletions
diff --git a/challenge-066/paulo-custodio/perl/ch-1.pl b/challenge-066/paulo-custodio/perl/ch-1.pl
index cb2e20a2bb..a7cce93c04 100644
--- a/challenge-066/paulo-custodio/perl/ch-1.pl
+++ b/challenge-066/paulo-custodio/perl/ch-1.pl
@@ -2,7 +2,7 @@
# Challenge 066
#
-# TASK #1 › Divide Integers
+# TASK #1 > Divide Integers
# Submitted by: Mohammad S Anwar
#
# You are given two integers $M and $N.
diff --git a/challenge-066/paulo-custodio/perl/ch-2.pl b/challenge-066/paulo-custodio/perl/ch-2.pl
index 8544b8b175..7af2581d91 100644
--- a/challenge-066/paulo-custodio/perl/ch-2.pl
+++ b/challenge-066/paulo-custodio/perl/ch-2.pl
@@ -2,7 +2,7 @@
# Challenge 066
#
-# TASK #2 › Power Integers
+# TASK #2 > Power Integers
# Submitted by: Mohammad S Anwar
#
# You are given an integer $N.
diff --git a/challenge-066/paulo-custodio/python/ch-1.py b/challenge-066/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..0a4de27eea
--- /dev/null
+++ b/challenge-066/paulo-custodio/python/ch-1.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+# Challenge 066
+#
+# TASK #1 > Divide Integers
+# Submitted by: Mohammad S Anwar
+#
+# You are given two integers $M and $N.
+#
+# Write a script to divide the given two integers i.e. $M / $N without using
+# multiplication, division and mod operator and return the floor of the result
+# of the division.
+#
+# Example 1:
+# Input: $M = 5, $N = 2
+# Output: 2
+# Example 2:
+# Input: $M = -5, $N = 2
+# Output: -3
+# Example 3:
+# Input: $M = -5, $N = -2
+# Output: 2
+
+import sys
+
+def divide1(m, n):
+ q = 0
+ while m >= n:
+ m -= n
+ q += 1
+ r = m
+ return q, r
+
+def divide(m, n):
+ q, r = divide1(abs(m), abs(n))
+ if m>=0 and n<0 or m<0 and n>=0:
+ q = -q
+ if r != 0:
+ q -= 1
+ return q
+
+M, N = map(int, sys.argv[1:])
+print(divide(M, N))
diff --git a/challenge-066/paulo-custodio/python/ch-2.py b/challenge-066/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..50d2aa2100
--- /dev/null
+++ b/challenge-066/paulo-custodio/python/ch-2.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+# Challenge 066
+#
+# TASK #2 > Power Integers
+# Submitted by: Mohammad S Anwar
+#
+# You are given an integer $N.
+#
+# Write a script to check if the given number can be expressed as mn where m and
+# n are positive integers. Otherwise print 0.
+#
+# Please make sure m > 1 and n > 1.
+#
+# BONUS: If there are more than one ways to express the given number then print
+# all possible solutions.
+#
+# Example 1:
+# For given $N = 9, it should print 32 or 3^2.
+#
+# Example 2:
+# For given $N = 45, it should print 0.
+#
+# Example 3:
+# For given $N = 64, it should print all or one of 8^2 or 2^6 or 4^3.
+
+import sys
+from math import sqrt
+
+def show_powers(n):
+ has_solution = False
+ for b in range(2, int(sqrt(n))+1):
+ for e in range(2, n):
+ if b**e == n:
+ print(str(b)+"^"+str(e))
+ has_solution = True
+ if not has_solution:
+ print(0)
+
+N = int(sys.argv[1])
+show_powers(N)