aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-167/paulo-custodio/python/ch-2.py2
-rw-r--r--challenge-168/paulo-custodio/perl/ch-1.pl4
-rw-r--r--challenge-168/paulo-custodio/perl/ch-2.pl8
-rw-r--r--challenge-168/paulo-custodio/python/ch-1.py60
-rw-r--r--challenge-168/paulo-custodio/python/ch-2.py64
-rw-r--r--challenge-169/paulo-custodio/perl/ch-1.pl4
-rw-r--r--challenge-169/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-169/paulo-custodio/python/ch-1.py76
-rw-r--r--challenge-169/paulo-custodio/python/ch-2.py95
-rw-r--r--challenge-170/paulo-custodio/perl/ch-1.pl8
-rw-r--r--challenge-170/paulo-custodio/perl/ch-2.pl4
-rw-r--r--challenge-170/paulo-custodio/python/ch-1.py52
-rw-r--r--challenge-170/paulo-custodio/python/ch-2.py80
-rw-r--r--challenge-171/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-171/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-171/paulo-custodio/python/ch-1.py54
-rw-r--r--challenge-171/paulo-custodio/python/ch-2.py32
-rw-r--r--challenge-172/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-172/paulo-custodio/perl/ch-2.pl4
-rw-r--r--challenge-172/paulo-custodio/python/ch-1.py90
-rw-r--r--challenge-172/paulo-custodio/python/ch-2.py32
-rw-r--r--challenge-172/paulo-custodio/t/test-2.yaml2
-rw-r--r--challenge-173/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-173/paulo-custodio/perl/ch-2.pl4
-rw-r--r--challenge-173/paulo-custodio/python/ch-1.py33
-rw-r--r--challenge-173/paulo-custodio/python/ch-2.py37
-rw-r--r--challenge-174/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-174/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-174/paulo-custodio/python/ch-1.py36
-rw-r--r--challenge-174/paulo-custodio/python/ch-2.py66
30 files changed, 834 insertions, 27 deletions
diff --git a/challenge-167/paulo-custodio/python/ch-2.py b/challenge-167/paulo-custodio/python/ch-2.py
index 1a8fc16a90..616c4080cc 100644
--- a/challenge-167/paulo-custodio/python/ch-2.py
+++ b/challenge-167/paulo-custodio/python/ch-2.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl
+#!/usr/bin/env python3
# Challenge 167
#
diff --git a/challenge-168/paulo-custodio/perl/ch-1.pl b/challenge-168/paulo-custodio/perl/ch-1.pl
index eda2430282..ca521979bc 100644
--- a/challenge-168/paulo-custodio/perl/ch-1.pl
+++ b/challenge-168/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 168
#
@@ -6,7 +6,7 @@
# Submitted by: Roger Bell_West
#
# The Perrin sequence is defined to start with [3, 0, 2]; after that, term N is
-# the sum of terms N-2 and N-3. (So it continues 3, 2, 5, 5, 7, ….)
+# the sum of terms N-2 and N-3. (So it continues 3, 2, 5, 5, 7, ....)
#
# A Perrin prime is a number in the Perrin sequence which is also a prime
# number.
diff --git a/challenge-168/paulo-custodio/perl/ch-2.pl b/challenge-168/paulo-custodio/perl/ch-2.pl
index b3ce77932c..427fafa330 100644
--- a/challenge-168/paulo-custodio/perl/ch-2.pl
+++ b/challenge-168/paulo-custodio/perl/ch-2.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 168
#
@@ -18,9 +18,9 @@
#
# As given in the Wikipedia page,
#
-# HP(10) = 773, as 10 factors as 2×5 yielding HP10(1) = 25, 25 factors as 5×5
-# yielding HP10(2) = HP25(1) = 55, 55 = 5×11 implies HP10(3) = HP25(2) = HP55(1)
-# = 511, and 511 = 7×73 gives HP10(4) = HP25(3) = HP55(2) = HP511(1) = 773, a
+# HP(10) = 773, as 10 factors as 2x5 yielding HP10(1) = 25, 25 factors as 5x5
+# yielding HP10(2) = HP25(1) = 55, 55 = 5x11 implies HP10(3) = HP25(2) = HP55(1)
+# = 511, and 511 = 7x73 gives HP10(4) = HP25(3) = HP55(2) = HP511(1) = 773, a
# prime number.
use Modern::Perl;
diff --git a/challenge-168/paulo-custodio/python/ch-1.py b/challenge-168/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..631b6eea96
--- /dev/null
+++ b/challenge-168/paulo-custodio/python/ch-1.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+
+# Challenge 168
+#
+# Task 1: Perrin Prime
+# Submitted by: Roger Bell_West
+#
+# The Perrin sequence is defined to start with [3, 0, 2]; after that, term N is
+# the sum of terms N-2 and N-3. (So it continues 3, 2, 5, 5, 7, ....)
+#
+# A Perrin prime is a number in the Perrin sequence which is also a prime
+# number.
+#
+# Calculate the first 13 Perrin Primes.
+#
+# f(13) = [2, 3, 5, 7, 17, 29, 277, 367, 853, 14197, 43721, 1442968193,
+# 792606555396977]
+
+def is_prime(n):
+ if n <= 1:
+ return False
+ if n <= 3:
+ return True
+ if n % 2 == 0 or n % 3 == 0:
+ return False
+ i = 5
+ while i * i <= n:
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ i += 6
+ return True
+
+def perrin_seq():
+ t = [3, 0, 2]
+ def next_perrin():
+ t.append(t[-2] + t[-3])
+ return t.pop(0)
+ return next_perrin
+
+def perrin_prime_seq():
+ it = perrin_seq()
+ seen = {}
+ def next_perrin_prime():
+ while True:
+ n = it()
+ if is_prime(n) and n not in seen:
+ seen[n] = True
+ return n
+ return next_perrin_prime
+
+import sys
+
+if len(sys.argv) != 2:
+ raise ValueError("usage: ch-1.py n")
+n = int(sys.argv[1])
+pp = []
+it = perrin_prime_seq()
+while len(pp) < n:
+ pp.append(it())
+print(", ".join(map(str, sorted(pp))))
diff --git a/challenge-168/paulo-custodio/python/ch-2.py b/challenge-168/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..75f56e23b6
--- /dev/null
+++ b/challenge-168/paulo-custodio/python/ch-2.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+# Challenge 168
+#
+# Task 2: Home Prime
+# Submitted by: Mohammad S Anwar
+#
+# You are given an integer greater than 1.
+#
+# Write a script to find the home prime of the given number.
+#
+# In number theory, the home prime HP(n) of an integer n greater than 1 is the
+# prime number obtained by repeatedly factoring the increasing concatenation of
+# prime factors including repetitions.
+#
+# Further information can be found on Wikipedia and OEIS.
+# Example
+#
+# As given in the Wikipedia page,
+#
+# HP(10) = 773, as 10 factors as 2x5 yielding HP10(1) = 25, 25 factors as 5x5
+# yielding HP10(2) = HP25(1) = 55, 55 = 5x11 implies HP10(3) = HP25(2) = HP55(1)
+# = 511, and 511 = 7x73 gives HP10(4) = HP25(3) = HP55(2) = HP511(1) = 773, a
+# prime number.
+
+def is_prime(n):
+ if n <= 1:
+ return False
+ if n <= 3:
+ return True
+ if n % 2 == 0 or n % 3 == 0:
+ return False
+ i = 5
+ while i * i <= n:
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ i += 6
+ return True
+
+def prime_factors(n):
+ factors = []
+ p = 0
+ while n > 1:
+ p += 1
+ while not is_prime(p):
+ p += 1
+ while n % p == 0:
+ factors.append(p)
+ n //= p
+ return factors
+
+def home_prime(n):
+ if n <= 1:
+ raise ValueError("Input must be greater than 1")
+ while not is_prime(n):
+ factors = prime_factors(n)
+ n = int(''.join(map(str, factors)))
+ return n
+
+import sys
+
+if len(sys.argv) != 2:
+ raise ValueError("usage: script.py n")
+print(home_prime(int(sys.argv[1])))
diff --git a/challenge-169/paulo-custodio/perl/ch-1.pl b/challenge-169/paulo-custodio/perl/ch-1.pl
index 313305f986..058a608817 100644
--- a/challenge-169/paulo-custodio/perl/ch-1.pl
+++ b/challenge-169/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 169
#
@@ -9,7 +9,7 @@
#
# Brilliant numbers are numbers with two prime factors of the same length.
#
-# The number should have exactly two prime factors, i.e. it’s the product of two
+# The number should have exactly two prime factors, i.e. it's the product of two
# primes of the same length.
#
# For example,
diff --git a/challenge-169/paulo-custodio/perl/ch-2.pl b/challenge-169/paulo-custodio/perl/ch-2.pl
index e049f4f458..bf1625cd34 100644
--- a/challenge-169/paulo-custodio/perl/ch-2.pl
+++ b/challenge-169/paulo-custodio/perl/ch-2.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 169
#
diff --git a/challenge-169/paulo-custodio/python/ch-1.py b/challenge-169/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..37ef60de29
--- /dev/null
+++ b/challenge-169/paulo-custodio/python/ch-1.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+
+# Challenge 169
+#
+# Task 1: Brilliant Numbers
+# Submitted by: Mohammad S Anwar
+#
+# Write a script to generate first 20 Brilliant Numbers.
+#
+# Brilliant numbers are numbers with two prime factors of the same length.
+#
+# The number should have exactly two prime factors, i.e. it's the product of two
+# primes of the same length.
+#
+# For example,
+#
+# 24287 = 149 x 163
+# 24289 = 107 x 227
+#
+# Therefore 24287 and 24289 are 2-brilliant numbers.
+# These two brilliant numbers happen to be consecutive as there are no even
+# brilliant numbers greater than 14.
+#
+#
+# Output
+#
+# 4, 6, 9, 10, 14, 15, 21, 25, 35, 49, 121, 143, 169, 187, 209, 221, 247, 253,
+# 289, 299
+
+import sys
+
+def is_prime(n):
+ if n <= 1:
+ return False
+ if n <= 3:
+ return True
+ if n % 2 == 0 or n % 3 == 0:
+ return False
+ i = 5
+ while i * i <= n:
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ i += 6
+ return True
+
+def prime_factors(n):
+ factors = []
+ p = 0
+ while n > 1:
+ p += 1
+ while not is_prime(p):
+ p += 1
+ while n % p == 0:
+ factors.append(p)
+ n //= p
+ return factors
+
+def is_brillant(n):
+ factors = prime_factors(n)
+ return len(factors) == 2 and is_prime(factors[0]) and is_prime(factors[1]) and len(str(factors[0])) == len(str(factors[1]))
+
+def brillant_seq():
+ n = 1
+ while True:
+ n += 1
+ if is_brillant(n):
+ yield n
+
+if len(sys.argv) != 2:
+ raise ValueError("usage: ch-1.py n")
+n = int(sys.argv[1])
+brillant = []
+it = brillant_seq()
+while len(brillant) < n:
+ brillant.append(next(it))
+print(", ".join(map(str, brillant)))
diff --git a/challenge-169/paulo-custodio/python/ch-2.py b/challenge-169/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..aca0a73fd8
--- /dev/null
+++ b/challenge-169/paulo-custodio/python/ch-2.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python3
+
+# Challenge 169
+#
+# Task 2: Achilles Numbers
+# Submitted by: Mohammad S Anwar
+#
+# Write a script to generate first 20 Achilles Numbers. Please checkout wikipedia
+# for more information.
+#
+# An Achilles number is a number that is powerful but imperfect (not a
+# perfect power). Named after Achilles, a hero of the Trojan war, who was
+# also powerful but imperfect.
+#
+# A positive integer n is a powerful number if, for every prime factor p of
+# n, p^2 is also a divisor.
+#
+# A number is a perfect power if it has any integer roots (square root, cube
+# root, etc.).
+#
+# For example 36 factors to (2, 2, 3, 3) - every prime factor (2, 3) also has its
+# square as a divisor (4, 9). But 36 has an integer square root, 6, so the number
+# is a perfect power.
+#
+# But 72 factors to (2, 2, 2, 3, 3); it similarly has 4 and 9 as divisors, but it
+# has no integer roots. This is an Achilles number.
+#
+# Output
+#
+# 72, 108, 200, 288, 392, 432, 500, 648, 675, 800, 864, 968, 972, 1125,
+# 1152, 1323, 1352, 1372, 1568, 1800
+
+def is_prime(n):
+ if n <= 1:
+ return False
+ if n <= 3:
+ return True
+ if n % 2 == 0 or n % 3 == 0:
+ return False
+ i = 5
+ while i * i <= n:
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ i += 6
+ return True
+
+def prime_factors(n):
+ factors = []
+ p = 0
+ while n > 1:
+ p += 1
+ while not is_prime(p):
+ p += 1
+ while n % p == 0:
+ factors.append(p)
+ n //= p
+ return factors
+
+def is_powerfull(n):
+ factors = prime_factors(n)
+ for factor in factors:
+ if n % (factor * factor) != 0:
+ return False
+ return True
+
+def is_perfect(n):
+ for e in range(2, n + 1):
+ for b in range(1, n + 1):
+ power = b ** e
+ if power == n:
+ return True
+ if power > n:
+ break
+ return False
+
+def is_aquilles(n):
+ return is_powerfull(n) and not is_perfect(n)
+
+def aquilles_seq():
+ n = 1
+ while True:
+ n += 1
+ if is_aquilles(n):
+ yield n
+
+import sys
+
+if len(sys.argv) != 2:
+ raise ValueError("usage: ch-2.py n")
+n = int(sys.argv[1])
+aquilles = []
+it = aquilles_seq()
+while len(aquilles) < n:
+ aquilles.append(next(it))
+print(", ".join(map(str, aquilles)))
diff --git a/challenge-170/paulo-custodio/perl/ch-1.pl b/challenge-170/paulo-custodio/perl/ch-1.pl
index 4d36966785..3d07569f3b 100644
--- a/challenge-170/paulo-custodio/perl/ch-1.pl
+++ b/challenge-170/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 170
#
@@ -14,9 +14,9 @@
#
# P(0) = 1 (1)
# P(1) = 2 (1x2)
-# P(2) = 6 (1x2×3)
-# P(3) = 30 (1x2×3×5)
-# P(4) = 210 (1x2×3×5×7)
+# P(2) = 6 (1x2x3)
+# P(3) = 30 (1x2x3x5)
+# P(4) = 210 (1x2x3x5x7)
use Modern::Perl;
diff --git a/challenge-170/paulo-custodio/perl/ch-2.pl b/challenge-170/paulo-custodio/perl/ch-2.pl
index dfff30bef8..92e0d5b3c2 100644
--- a/challenge-170/paulo-custodio/perl/ch-2.pl
+++ b/challenge-170/paulo-custodio/perl/ch-2.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 170
#
@@ -61,7 +61,7 @@ sub parse_input {
sub kronecker_product {
my($a, $b) = @_;
my $wa = @{$a->[0]}; my $ha = @$a;
- my $wb = @{$b->[0]}; my $hb = @$a;
+ my $wb = @{$b->[0]}; my $hb = @$b;
my @prod;
for my $ar (0..$ha-1) {
for my $ac (0..$wa-1) {
diff --git a/challenge-170/paulo-custodio/python/ch-1.py b/challenge-170/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..1b2a973b87
--- /dev/null
+++ b/challenge-170/paulo-custodio/python/ch-1.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+
+# Challenge 170
+#
+# Task 1: Primorial Numbers
+# Submitted by: Mohammad S Anwar
+#
+# Write a script to generate first 10 Primorial Numbers.
+#
+# Primorial numbers are those formed by multiplying successive prime numbers.
+#
+#
+# For example,
+#
+# P(0) = 1 (1)
+# P(1) = 2 (1x2)
+# P(2) = 6 (1x2x3)
+# P(3) = 30 (1x2x3x5)
+# P(4) = 210 (1x2x3x5x7)
+
+import sys
+
+def is_prime(n):
+ if n == 2 or n == 3:
+ return True
+ if n <= 1 or n % 2 == 0 or n % 3 == 0:
+ return False
+ i = 5
+ while i * i <= n:
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ i += 6
+ return True
+
+def next_prime(p):
+ p += 1
+ while not is_prime(p):
+ p += 1
+ return p
+
+def primorial_numbers(n):
+ primorial = [1]
+ p = 1
+ while len(primorial) < n:
+ p = next_prime(p)
+ primorial.append(primorial[-1] * p)
+ return primorial
+
+if len(sys.argv) != 2:
+ raise ValueError("usage: ch-1.py n")
+n = int(sys.argv[1])
+print(", ".join(map(str, primorial_numbers(n))))
diff --git a/challenge-170/paulo-custodio/python/ch-2.py b/challenge-170/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..ed5be6a669
--- /dev/null
+++ b/challenge-170/paulo-custodio/python/ch-2.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+
+# Challenge 170
+#
+# Task 2: Kronecker Product
+# Submitted by: Mohammad S Anwar
+#
+# You are given 2 matrices.
+#
+# Write a script to implement Kronecker Product on the given 2 matrices.
+#
+# For more information, please refer wikipedia page.
+#
+# For example,
+#
+# A = [ 1 2 ]
+# [ 3 4 ]
+#
+# B = [ 5 6 ]
+# [ 7 8 ]
+#
+# A x B = [ 1 x [ 5 6 ] 2 x [ 5 6 ] ]
+# [ [ 7 8 ] [ 7 8 ] ]
+# [ 3 x [ 5 6 ] 4 x [ 5 6 ] ]
+# [ [ 7 8 ] [ 7 8 ] ]
+#
+# = [ 1x5 1x6 2x5 2x6 ]
+# [ 1x7 1x8 2x7 2x8 ]
+# [ 3x5 3x6 4x5 4x6 ]
+# [ 3x7 3x8 4x7 4x8 ]
+#
+# = [ 5 6 10 12 ]
+# [ 7 8 14 16 ]
+# [ 15 18 20 24 ]
+# [ 21 24 28 32 ]
+
+import sys
+import re
+
+def parse_matrix(line):
+ mx = []
+ while re.match(r'^\s*$', line):
+ line = sys.stdin.readline()
+ line, count = re.subn(r'^\s*\w+\s*=\s*', '', line)
+ if count == 0:
+ raise ValueError("assignment expected")
+ while found := re.match(r'^\s*\[([\d\s]+)\]\s*$', line):
+ row = [int(x) for x in found.group(1).split()]
+ mx.append(row)
+ line = sys.stdin.readline()
+ return mx, line
+
+def parse_input():
+ line = sys.stdin.readline()
+ a, line = parse_matrix(line)
+ b, line = parse_matrix(line)
+ return a, b
+
+def print_matrix(mx):
+ for row in mx:
+ print("[ "+ " ".join([str(x) for x in row]) +" ]")
+
+def kronecker_product(a, b):
+ wa = len(a[0])
+ ha = len(a)
+ wb = len(b[0])
+ hb = len(b)
+ prod = [[0 for _ in range(wa*wb)] for _ in range(ha*hb)]
+ for ar in range(ha):
+ for ac in range(wa):
+ for br in range(hb):
+ for bc in range(wb):
+ tr = ar*hb + br
+ tc = ac*wb + bc
+ prod[tr][tc] = a[ar][ac] * b[br][bc]
+ return prod
+
+a, b = parse_input()
+p = kronecker_product(a, b)
+print_matrix(p)
diff --git a/challenge-171/paulo-custodio/perl/ch-1.pl b/challenge-171/paulo-custodio/perl/ch-1.pl
index b67f270336..735f7b2082 100644
--- a/challenge-171/paulo-custodio/perl/ch-1.pl
+++ b/challenge-171/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 171
#
diff --git a/challenge-171/paulo-custodio/perl/ch-2.pl b/challenge-171/paulo-custodio/perl/ch-2.pl
index 45c3da0abf..96387742bc 100644
--- a/challenge-171/paulo-custodio/perl/ch-2.pl
+++ b/challenge-171/paulo-custodio/perl/ch-2.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 171
#
diff --git a/challenge-171/paulo-custodio/python/ch-1.py b/challenge-171/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..a84a80698e
--- /dev/null
+++ b/challenge-171/paulo-custodio/python/ch-1.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+
+# Challenge 171
+#
+# Task 1: Abundant Number
+# Submitted by: Mohammad S Anwar
+#
+# Write a script to generate first 20 Abundant Odd Numbers.
+#
+# According to wikipedia,
+#
+# A number n for which the sum of divisors s(n) > 2n, or, equivalently, the
+# sum of proper divisors (or aliquot sum) s(n) > n.
+#
+#
+# For example, 945 is the first Abundant Odd Number.
+#
+# Sum of divisors:
+# 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315 = 975
+
+import sys
+import math
+from functools import reduce
+
+def divisors(n):
+ div_low = []
+ div_high = []
+ for i in range(1, int(math.sqrt(n)) + 1):
+ if n % i == 0:
+ div_low.append(i)
+ if n // i != i:
+ div_high.insert(0, n // i)
+ return div_low + div_high
+
+def proper_divisors(n):
+ div = divisors(n)
+ return div[:-1]
+
+def is_abundant(n):
+ return sum(proper_divisors(n)) > n
+
+def abundant_numbers(N):
+ abundant = []
+ n = 1
+ while len(abundant) < N:
+ if is_abundant(n):
+ abundant.append(n)
+ n += 1
+ return abundant
+
+if len(sys.argv) != 2:
+ raise ValueError("usage: script.py n")
+N = int(sys.argv[1])
+print(", ".join(map(str, abundant_numbers(N))))
diff --git a/challenge-171/paulo-custodio/python/ch-2.py b/challenge-171/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..f780acf173
--- /dev/null
+++ b/challenge-171/paulo-custodio/python/ch-2.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+# Challenge 171
+#
+# Task 2: First-class Function
+# Submitted by: Mohammad S Anwar
+#
+# Create sub compose($f, $g) which takes in two parameters $f and $g as
+# subroutine refs and returns subroutine ref i.e. compose($f, $g)->($x) =
+# $f->($g->($x))
+#
+# e.g.
+#
+# $f = (one or more parameters function)
+# $g = (one or more parameters function)
+#
+# $h = compose($f, $g)
+# $f->($g->($x,$y, ..)) == $h->($x, $y, ..) for any $x, $y, ...
+
+import sys
+
+def compose(f, g):
+ return lambda x: f(g(x))
+
+def times3(x):
+ return 3 * x
+
+def times5(x):
+ return 5 * x
+
+h = compose(times3, times5)
+print(h(int(int(sys.argv[1]))))
diff --git a/challenge-172/paulo-custodio/perl/ch-1.pl b/challenge-172/paulo-custodio/perl/ch-1.pl
index 6753187f1a..1a28191ff2 100644
--- a/challenge-172/paulo-custodio/perl/ch-1.pl
+++ b/challenge-172/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 172
#
diff --git a/challenge-172/paulo-custodio/perl/ch-2.pl b/challenge-172/paulo-custodio/perl/ch-2.pl
index a7a6852c2e..1f4bf144c9 100644
--- a/challenge-172/paulo-custodio/perl/ch-2.pl
+++ b/challenge-172/paulo-custodio/perl/ch-2.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 172
#
@@ -40,4 +40,4 @@ sub five_number_summary {
return ($n[0], lower_quartile(@n), median(@n), upper_quartile(@n), $n[-1]);
}
-say join ", ", five_number_summary(@ARGV);
+say join ", ", map {sprintf("%.1f", $_)} five_number_summary(@ARGV);
diff --git a/challenge-172/paulo-custodio/python/ch-1.py b/challenge-172/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..7bc35bc760
--- /dev/null
+++ b/challenge-172/paulo-custodio/python/ch-1.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python3
+
+# Challenge 172
+#
+# Task 1: Prime Partition
+# Submitted by: Mohammad S Anwar
+#
+# You are given two positive integers, $m and $n.
+#
+# Write a script to find out the Prime Partition of the given number. No
+# duplicates allowed.
+#
+# For example,
+#
+# Input: $m = 18, $n = 2
+# Output: 5, 13 or 7, 11
+#
+# Input: $m = 19, $n = 3
+# Output: 3, 5, 11
+
+import sys
+from itertools import count
+from functools import reduce
+
+def is_prime(n):
+ if n <= 1:
+ return False
+ if n <= 3:
+ return True
+ if n % 2 == 0 or n % 3 == 0:
+ return False
+ for i in range(5, int(n**0.5) + 1, 6):
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ return True
+
+def next_prime(n):
+ if n <= 1:
+ return 2
+ p = n
+ while True:
+ p += 1
+ if is_prime(p):
+ return p
+
+def primes(n):
+ p = 2
+ prime_list = []
+ while p <= n:
+ prime_list.append(p)
+ p = next_prime(p)
+ return prime_list
+
+def odometer_increment(limit, n):
+ i = len(n) - 1
+ while True:
+ n[i] += 1
+ if n[i] >= limit:
+ n[i] = 0
+ i -= 1
+ if i < 0:
+ n.insert(0, 0)
+ i = 0
+ else:
+ break
+ return n
+
+def has_duplicates(n):
+ seen = set()
+ for num in n:
+ if num in seen:
+ return True
+ seen.add(num)
+ return False
+
+def prime_partition(m, n):
+ prime_list = primes(m)
+ idx = [0] * n
+ while len(idx) == n:
+ if not has_duplicates(idx):
+ terms = [prime_list[i] for i in idx]
+ if sum(terms) == m:
+ return terms
+ idx = odometer_increment(len(prime_list), idx)
+ return []
+
+if len(sys.argv) != 3:
+ raise ValueError("usage: ch-1.py m n")
+m, n = map(int, sys.argv[1:])
+print(", ".join(map(str, prime_partition(m, n))))
diff --git a/challenge-172/paulo-custodio/python/ch-2.py b/challenge-172/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..d6de8fcc5b
--- /dev/null
+++ b/challenge-172/paulo-custodio/python/ch-2.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+# Challenge 172
+#
+# Task 2: Five-number Summary
+# Submitted by: Mohammad S Anwar
+#
+# You are given an array of integers.
+#
+# Write a script to compute the five-number summary of the given set of integers.
+#
+# You can find the definition and example in the wikipedia page.
+
+def median(n):
+ if len(n) % 2 == 0:
+ i = len(n) // 2
+ return (n[i - 1] + n[i]) / 2
+ else:
+ return n[len(n) // 2]
+
+def lower_quartile(n):
+ return median(n[:len(n) // 2])
+
+def upper_quartile(n):
+ return median(n[len(n) // 2:])
+
+def five_number_summary(n):
+ n.sort()
+ return (n[0], lower_quartile(n), median(n), upper_quartile(n), n[-1])
+
+import sys
+print(", ".join([f"{x:.1f}" for x in five_number_summary(list(map(float, sys.argv[1:])))]))
diff --git a/challenge-172/paulo-custodio/t/test-2.yaml b/challenge-172/paulo-custodio/t/test-2.yaml
index 7271a491ad..c840c8ef46 100644
--- a/challenge-172/paulo-custodio/t/test-2.yaml
+++ b/challenge-172/paulo-custodio/t/test-2.yaml
@@ -2,4 +2,4 @@
cleanup:
args: 0 0 1 2 63 61 27 13
input:
- output: 0, 0.5, 7.5, 44, 63
+ output: 0.0, 0.5, 7.5, 44.0, 63.0
diff --git a/challenge-173/paulo-custodio/perl/ch-1.pl b/challenge-173/paulo-custodio/perl/ch-1.pl
index caba1bf96d..859df10ea8 100644
--- a/challenge-173/paulo-custodio/perl/ch-1.pl
+++ b/challenge-173/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 173
#
diff --git a/challenge-173/paulo-custodio/perl/ch-2.pl b/challenge-173/paulo-custodio/perl/ch-2.pl