aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-11-11 16:43:10 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-11-11 16:43:10 +0000
commitc0d9658341be76934b2a8881ccaf7aeb5acbf9fa (patch)
treeded36c23b7b3c6836e1d0c644b455e76850c462e
parentd5e43718831c3dbbe896bb375ecfa2f731536717 (diff)
downloadperlweeklychallenge-club-c0d9658341be76934b2a8881ccaf7aeb5acbf9fa.tar.gz
perlweeklychallenge-club-c0d9658341be76934b2a8881ccaf7aeb5acbf9fa.tar.bz2
perlweeklychallenge-club-c0d9658341be76934b2a8881ccaf7aeb5acbf9fa.zip
Add Python solution to challenge 85
-rw-r--r--challenge-085/paulo-custodio/Makefile2
-rw-r--r--challenge-085/paulo-custodio/perl/ch-1.pl7
-rw-r--r--challenge-085/paulo-custodio/perl/ch-2.pl7
-rw-r--r--challenge-085/paulo-custodio/python/ch-1.py31
-rw-r--r--challenge-085/paulo-custodio/python/ch-2.py43
-rw-r--r--challenge-085/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-085/paulo-custodio/t/test-2.yaml15
7 files changed, 114 insertions, 6 deletions
diff --git a/challenge-085/paulo-custodio/Makefile b/challenge-085/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-085/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-085/paulo-custodio/perl/ch-1.pl b/challenge-085/paulo-custodio/perl/ch-1.pl
index a471b54e85..6037ae6976 100644
--- a/challenge-085/paulo-custodio/perl/ch-1.pl
+++ b/challenge-085/paulo-custodio/perl/ch-1.pl
@@ -1,12 +1,13 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 085
#
-# TASK #1 › Triplet Sum
+# TASK #1 > Triplet Sum
# Submitted by: Mohammad S Anwar
# You are given an array of real numbers greater than zero.
#
-# Write a script to find if there exists a triplet (a,b,c) such that 1 < a+b+c < 2. Print 1 if you succeed otherwise 0.
+# Write a script to find if there exists a triplet (a,b,c) such that
+# 1 < a+b+c < 2. Print 1 if you succeed otherwise 0.
#
# Example 1:
# Input: @R = (1.2, 0.4, 0.1, 2.5)
diff --git a/challenge-085/paulo-custodio/perl/ch-2.pl b/challenge-085/paulo-custodio/perl/ch-2.pl
index c0a16a4221..4b0f2447f4 100644
--- a/challenge-085/paulo-custodio/perl/ch-2.pl
+++ b/challenge-085/paulo-custodio/perl/ch-2.pl
@@ -1,12 +1,13 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 085
#
-# TASK #2 › Power of Two Integers
+# TASK #2 > Power of Two Integers
# Submitted by: Mohammad S Anwar
# You are given a positive integer $N.
#
-# Write a script to find if it can be expressed as a ** b where a > 0 and b > 1. Print 1 if you succeed otherwise 0.
+# Write a script to find if it can be expressed as a ** b where
+# a > 0 and b > 1. Print 1 if you succeed otherwise 0.
#
# Example 1:
# Input: 8
diff --git a/challenge-085/paulo-custodio/python/ch-1.py b/challenge-085/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..54f9e1cd1b
--- /dev/null
+++ b/challenge-085/paulo-custodio/python/ch-1.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+# Challenge 085
+#
+# TASK #1 > Triplet Sum
+# Submitted by: Mohammad S Anwar
+# You are given an array of real numbers greater than zero.
+#
+# Write a script to find if there exists a triplet (a,b,c) such that
+# 1 < a+b+c < 2. Print 1 if you succeed otherwise 0.
+#
+# Example 1:
+# Input: @R = (1.2, 0.4, 0.1, 2.5)
+# Output: 1 as 1 < 1.2 + 0.4 + 0.1 < 2
+# Example 2:
+# Input: @R = (0.2, 1.5, 0.9, 1.1)
+# Output: 0
+# Example 3:
+# Input: @R = (0.5, 1.1, 0.3, 0.7)
+# Output: 1 as 1 < 0.5 + 1.1 + 0.3 < 2
+
+import sys
+from itertools import combinations
+
+def check(nums):
+ for combin in combinations(nums, 3):
+ if 1.0 < sum(combin) < 2.0:
+ return True
+ return False
+
+print(1 if check([float(x) for x in sys.argv[1:]]) else 0)
diff --git a/challenge-085/paulo-custodio/python/ch-2.py b/challenge-085/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..ef869c12f8
--- /dev/null
+++ b/challenge-085/paulo-custodio/python/ch-2.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+# Challenge 085
+#
+# TASK #2 > Power of Two Integers
+# Submitted by: Mohammad S Anwar
+# You are given a positive integer $N.
+#
+# Write a script to find if it can be expressed as a ** b where
+# a > 0 and b > 1. Print 1 if you succeed otherwise 0.
+#
+# Example 1:
+# Input: 8
+# Output: 1 as 8 = 2 ** 3
+# Example 2:
+# Input: 15
+# Output: 0
+# Example 3:
+# Input: 125
+# Output: 1 as 125 = 5 ** 3
+
+import sys
+
+def get_prime_factors(n):
+ i = 2
+ prime_factors = []
+ while i*i <= n:
+ if n%i == 0:
+ prime_factors.append(i)
+ n //= i
+ else:
+ i += 1
+
+ if n>1:
+ prime_factors.append(n)
+
+ return prime_factors
+
+def is_perfect_power(n):
+ factors = list(set(get_prime_factors(n)))
+ return len(factors)==1
+
+print(1 if is_perfect_power(int(sys.argv[1])) else 0)
diff --git a/challenge-085/paulo-custodio/t/test-1.yaml b/challenge-085/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..f382a0db0c
--- /dev/null
+++ b/challenge-085/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 1.2 0.4 0.1 2.5
+ input:
+ output: 1
+- setup:
+ cleanup:
+ args: 0.2 1.5 0.9 1.1
+ input:
+ output: 0
+- setup:
+ cleanup:
+ args: 0.5 1.1 0.3 0.7
+ input:
+ output: 1
diff --git a/challenge-085/paulo-custodio/t/test-2.yaml b/challenge-085/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..1e3f9f6071
--- /dev/null
+++ b/challenge-085/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 8
+ input:
+ output: 1
+- setup:
+ cleanup:
+ args: 15
+ input:
+ output: 0
+- setup:
+ cleanup:
+ args: 125
+ input:
+ output: 1