aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-001/paulo-custodio/go.pl5
-rw-r--r--challenge-065/paulo-custodio/python/ch-2.py2
-rw-r--r--challenge-154/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-154/paulo-custodio/perl/ch-2.pl4
-rw-r--r--challenge-154/paulo-custodio/python/ch-1.py25
-rw-r--r--challenge-154/paulo-custodio/python/ch-2.py57
-rw-r--r--challenge-155/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-155/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-155/paulo-custodio/python/ch-1.py32
-rw-r--r--challenge-155/paulo-custodio/python/ch-2.py57
-rw-r--r--challenge-156/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-156/paulo-custodio/python/ch-1.py35
-rw-r--r--challenge-156/paulo-custodio/python/ch-2.py59
-rw-r--r--challenge-157/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-157/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-157/paulo-custodio/python/ch-1.py46
-rw-r--r--challenge-157/paulo-custodio/python/ch-2.py53
-rw-r--r--challenge-158/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-158/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-158/paulo-custodio/python/ch-1.py27
-rw-r--r--challenge-158/paulo-custodio/python/ch-2.py31
-rw-r--r--challenge-159/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-159/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-159/paulo-custodio/python/ch-1.py38
-rw-r--r--challenge-159/paulo-custodio/python/ch-2.py26
-rw-r--r--challenge-160/paulo-custodio/perl/ch-1.pl4
-rw-r--r--challenge-160/paulo-custodio/perl/ch-2.pl6
-rw-r--r--challenge-160/paulo-custodio/python/ch-1.py44
-rw-r--r--challenge-160/paulo-custodio/python/ch-2.py40
-rw-r--r--challenge-162/paulo-custodio/python/ch-1.py28
-rw-r--r--challenge-162/paulo-custodio/python/ch-2.py105
-rw-r--r--challenge-163/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-163/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-163/paulo-custodio/python/ch-1.py33
-rw-r--r--challenge-163/paulo-custodio/python/ch-2.py51
-rw-r--r--challenge-164/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-164/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-164/paulo-custodio/python/ch-1.py49
-rw-r--r--challenge-164/paulo-custodio/python/ch-2.py52
39 files changed, 913 insertions, 24 deletions
diff --git a/challenge-001/paulo-custodio/go.pl b/challenge-001/paulo-custodio/go.pl
index 3904778b45..b41860b43a 100644
--- a/challenge-001/paulo-custodio/go.pl
+++ b/challenge-001/paulo-custodio/go.pl
@@ -9,8 +9,9 @@ my $nr = sprintf("%03d", $ARGV[0]);
path("challenge-$nr/paulo-custodio")->mkpath;
#for my $dir (qw(ada awk basic bc brainfuck c cpp d forth fortran lua pascal perl python t)) {
-# path("challenge-$nr/paulo-custodio/$dir")->mkpath;
-#}
+for my $dir (qw( perl python t )) {
+ path("challenge-$nr/paulo-custodio/$dir")->mkpath;
+}
path("challenge-$nr/paulo-custodio/README")->spew("Solution by Paulo Custodio\n");
if (! -f "challenge-$nr/paulo-custodio/Makefile") {
diff --git a/challenge-065/paulo-custodio/python/ch-2.py b/challenge-065/paulo-custodio/python/ch-2.py
index 702ed4d413..7d037bdc0d 100644
--- a/challenge-065/paulo-custodio/python/ch-2.py
+++ b/challenge-065/paulo-custodio/python/ch-2.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl
+#!/usr/bin/env python3
# Challenge 065
#
diff --git a/challenge-154/paulo-custodio/perl/ch-1.pl b/challenge-154/paulo-custodio/perl/ch-1.pl
index 7176aa1fdf..1d84fcd558 100644
--- a/challenge-154/paulo-custodio/perl/ch-1.pl
+++ b/challenge-154/paulo-custodio/perl/ch-1.pl
@@ -2,7 +2,7 @@
# Challenge 154
#
-# TASK #1 › Missing Permutation
+# TASK #1 > Missing Permutation
# Submitted by: Mohammad S Anwar
# You are given possible permutations of the string 'PERL'.
#
diff --git a/challenge-154/paulo-custodio/perl/ch-2.pl b/challenge-154/paulo-custodio/perl/ch-2.pl
index c70b72378a..0b68acc1fa 100644
--- a/challenge-154/paulo-custodio/perl/ch-2.pl
+++ b/challenge-154/paulo-custodio/perl/ch-2.pl
@@ -2,9 +2,9 @@
# Challenge 154
#
-# TASK #2 › Padovan Prime
+# TASK #2 > Padovan Prime
# Submitted by: Mohammad S Anwar
-# A Padovan Prime is a Padovan Number that’s also prime.
+# A Padovan Prime is a Padovan Number that's also prime.
#
# In number theory, the Padovan sequence is the sequence of integers P(n)
# defined by the initial values.
diff --git a/challenge-154/paulo-custodio/python/ch-1.py b/challenge-154/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..1b121593e6
--- /dev/null
+++ b/challenge-154/paulo-custodio/python/ch-1.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+# Challenge 154
+#
+# TASK #1 > Missing Permutation
+# Submitted by: Mohammad S Anwar
+# You are given possible permutations of the string 'PERL'.
+#
+# PELR, PREL, PERL, PRLE, PLER, PLRE, EPRL, EPLR, ERPL,
+# ERLP, ELPR, ELRP, RPEL, RPLE, REPL, RELP, RLPE, RLEP,
+# LPER, LPRE, LEPR, LRPE, LREP
+# Write a script to find any permutations missing from the list.
+
+from itertools import permutations
+
+have = {
+ "PELR", "PREL", "PERL", "PRLE", "PLER", "PLRE", "EPRL", "EPLR", "ERPL",
+ "ERLP", "ELPR", "ELRP", "RPEL", "RPLE", "REPL", "RELP", "RLPE", "RLEP",
+ "LPER", "LPRE", "LEPR", "LRPE", "LREP"
+}
+
+all_permutations = {''.join(p) for p in permutations("PERL")}
+missing = sorted(set(all_permutations) - have)
+
+print(", ".join(missing))
diff --git a/challenge-154/paulo-custodio/python/ch-2.py b/challenge-154/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..0afb22504f
--- /dev/null
+++ b/challenge-154/paulo-custodio/python/ch-2.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+# Challenge 154
+#
+# TASK #2 > Padovan Prime
+# Submitted by: Mohammad S Anwar
+# A Padovan Prime is a Padovan Number that's also prime.
+#
+# In number theory, the Padovan sequence is the sequence of integers P(n)
+# defined by the initial values.
+#
+# P(0) = P(1) = P(2) = 1
+# and then followed by
+#
+# P(n) = P(n-2) + P(n-3)
+# First few Padovan Numbers are as below:
+#
+# 1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, ...
+# Write a script to compute first 10 distinct Padovan Primes.
+#
+# Expected Output
+# 2, 3, 5, 7, 37, 151, 3329, 23833, 13091204281, 3093215881333057
+
+from functools import lru_cache
+from sympy import isprime
+
+@lru_cache(None)
+def padovan(n):
+ if n < 3:
+ return 1
+ else:
+ return padovan(n - 2) + padovan(n - 3)
+
+def padovan_iter():
+ n = 0
+ while True:
+ n += 1
+ yield padovan(n)
+
+def padovan_prime_iter():
+ padovan_it = padovan_iter()
+ for got in padovan_it:
+ if isprime(got):
+ yield got
+
+def uniq_padovan_prime_it():
+ got = set()
+ padovan_prime_it = padovan_prime_iter()
+ while True:
+ for value in padovan_prime_it:
+ if value not in got:
+ got.add(value)
+ yield value
+
+it = uniq_padovan_prime_it()
+out = [next(it) for _ in range(10)]
+print(", ".join(map(str, out)))
diff --git a/challenge-155/paulo-custodio/perl/ch-1.pl b/challenge-155/paulo-custodio/perl/ch-1.pl
index ff00af24a0..80eb7c1565 100644
--- a/challenge-155/paulo-custodio/perl/ch-1.pl
+++ b/challenge-155/paulo-custodio/perl/ch-1.pl
@@ -2,7 +2,7 @@
# Challenge 155
#
-# TASK #1 › Fortunate Numbers
+# TASK #1 > Fortunate Numbers
# Submitted by: Mohammad S Anwar
# Write a script to produce first 8 Fortunate Numbers (unique and sorted).
#
diff --git a/challenge-155/paulo-custodio/perl/ch-2.pl b/challenge-155/paulo-custodio/perl/ch-2.pl
index 4ff1516026..fbaa92c2ee 100644
--- a/challenge-155/paulo-custodio/perl/ch-2.pl
+++ b/challenge-155/paulo-custodio/perl/ch-2.pl
@@ -2,7 +2,7 @@
# Challenge 155
#
-# TASK #2 › Pisano Period
+# TASK #2 > Pisano Period
# Submitted by: Mohammad S Anwar
# Write a script to find the period of the 3rd Pisano Period.
#
diff --git a/challenge-155/paulo-custodio/python/ch-1.py b/challenge-155/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..e1cdaebf76
--- /dev/null
+++ b/challenge-155/paulo-custodio/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+# Challenge 155
+#
+# TASK #1 > Fortunate Numbers
+# Submitted by: Mohammad S Anwar
+# Write a script to produce first 8 Fortunate Numbers (unique and sorted).
+#
+# According to Wikipedia
+#
+# A Fortunate number, named after Reo Fortune, is the smallest integer m > 1
+# such that, for a given positive integer n, pn# + m is a prime number, where
+# the primorial pn# is the product of the first n prime numbers.
+#
+# Expected Output
+# 3, 5, 7, 13, 17, 19, 23, 37
+
+from math import prod
+from sympy import isprime, nextprime
+
+fortunate = {}
+
+primes = [2]
+while len(fortunate) < 8:
+ p = prod(primes)
+ m = 2
+ while not isprime(p + m):
+ m += 1
+ fortunate[m] = 1
+ primes.append(nextprime(primes[-1]))
+
+print(", ".join(map(str, sorted(fortunate.keys()))))
diff --git a/challenge-155/paulo-custodio/python/ch-2.py b/challenge-155/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..f5408b05db
--- /dev/null
+++ b/challenge-155/paulo-custodio/python/ch-2.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+# Challenge 155
+#
+# TASK #2 > Pisano Period
+# Submitted by: Mohammad S Anwar
+# Write a script to find the period of the 3rd Pisano Period.
+#
+# In number theory, the nth Pisano period, written as p(n), is the period with
+# which the sequence of Fibonacci numbers taken modulo n repeats.
+#
+# The Fibonacci numbers are the numbers in the integer sequence:
+#
+# 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, ...
+# For any integer n, the sequence of Fibonacci numbers F(i) taken modulo n is
+# periodic. The Pisano period, denoted p(n), is the value of the period of this
+# sequence. For example, the sequence of Fibonacci numbers modulo 3 begins:
+#
+# 0, 1, 1, 2, 0, 2, 2, 1,
+# 0, 1, 1, 2, 0, 2, 2, 1,
+# 0, 1, 1, 2, 0, 2, 2, 1, ...
+# This sequence has period 8, so p(3) = 8.
+
+from math import isqrt
+
+order = 3
+
+def fibonacci_series(n):
+ fibs = [0, 1]
+ for i in range(2, n):
+ fibs.append(fibs[-1] + fibs[-2])
+ return fibs
+
+def is_period(period, n):
+ base = n[0:period]
+ ord1 = n[period:2*period]
+ ord2 = n[2*period:3*period]
+
+ if base != ord1:
+ return 0
+ if base != ord2:
+ return 0
+ return 1
+
+def find_period(n):
+ period = 1
+ while True:
+ if 3 * period > len(n):
+ return 0
+ if is_period(period, n):
+ return period
+ period += 1
+ return 0
+
+fibs = fibonacci_series(100)
+fibs_mod = [fib % order for fib in fibs]
+print(find_period(fibs_mod))
diff --git a/challenge-156/paulo-custodio/perl/ch-2.pl b/challenge-156/paulo-custodio/perl/ch-2.pl
index d16e291ea5..d77b690bbf 100644
--- a/challenge-156/paulo-custodio/perl/ch-2.pl
+++ b/challenge-156/paulo-custodio/perl/ch-2.pl
@@ -2,7 +2,7 @@
# Challenge 156
#
-# TASK #2 › Weird Number
+# TASK #2 > Weird Number
# Submitted by: Mohammad S Anwar
# You are given number, $n > 0.
#
diff --git a/challenge-156/paulo-custodio/python/ch-1.py b/challenge-156/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..dd16bf4390
--- /dev/null
+++ b/challenge-156/paulo-custodio/python/ch-1.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+
+# Challenge 156
+#
+# TASK #1 > Pernicious Numbers
+# Submitted by: Mohammad S Anwar
+# Write a script to permute first 10 Pernicious Numbers.
+#
+# A pernicious number is a positive integer which has prime number of ones in
+# its binary representation.
+#
+# The first pernicious number is 3 since binary representation of 3 = (11)
+# and 1 + 1 = 2, which is a prime.
+#
+# Expected Output
+# 3, 5, 6, 7, 9, 10, 11, 12, 13, 14
+
+from sympy import isprime
+
+def is_pernicious(n):
+ bin_n = bin(n)[2:] # Convert to binary and remove the '0b' prefix
+ ones = bin_n.count('1')
+ is_pernicious = isprime(ones)
+ return is_pernicious
+
+def first_pernicious(num):
+ out = []
+ n = 0
+ while len(out) < num:
+ if is_pernicious(n):
+ out.append(n)
+ n += 1
+ return out
+
+print(", ".join(map(str, first_pernicious(10))))
diff --git a/challenge-156/paulo-custodio/python/ch-2.py b/challenge-156/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..b198001956
--- /dev/null
+++ b/challenge-156/paulo-custodio/python/ch-2.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+# Challenge 156
+#
+# TASK #2 > Weird Number
+# Submitted by: Mohammad S Anwar
+# You are given number, $n > 0.
+#
+# Write a script to find out if the given number is a Weird Number.
+#
+# According to Wikipedia, it is defined as:
+#
+# The sum of the proper divisors (divisors including 1 but not itself) of the
+# number is greater than the number, but no subset of those divisors sums to
+# the number itself.
+#
+# Example 1:
+# Input: $n = 12
+# Output: 0
+#
+# Since the proper divisors of 12 are 1, 2, 3, 4, and 6, which sum to 16; but
+# 2 + 4 + 6 = 12.
+# Example 2:
+# Input: $n = 70
+# Output: 1
+#
+# As the proper divisors of 70 are 1, 2, 5, 7, 10, 14, and 35; these sum to
+# 74, but no subset of these sums to 70.
+
+import sys
+from itertools import combinations
+from math import isqrt
+
+def divisors(n):
+ divs = set()
+ for i in range(1, isqrt(n) + 1):
+ if n % i == 0:
+ divs.add(i)
+ divs.add(n // i)
+ return divs
+
+def proper_divisors(n):
+ return [d for d in divisors(n) if d != n]
+
+def check_no_subset_sums_n(n, div):
+ for k in range(1, len(div) + 1):
+ for combin in combinations(div, k):
+ if sum(combin) == n:
+ return False
+ return True
+
+def is_weird(n):
+ div = proper_divisors(n)
+ if sum(div) <= n:
+ return False
+ return check_no_subset_sums_n(n, div)
+
+n = int(sys.argv[1])
+print(1 if is_weird(n) else 0)
diff --git a/challenge-157/paulo-custodio/perl/ch-1.pl b/challenge-157/paulo-custodio/perl/ch-1.pl
index b6b2cdd4e6..36199d209e 100644
--- a/challenge-157/paulo-custodio/perl/ch-1.pl
+++ b/challenge-157/paulo-custodio/perl/ch-1.pl
@@ -2,7 +2,7 @@
# Challenge 157
#
-# TASK #1 › Pythagorean Means
+# TASK #1 > Pythagorean Means
# Submitted by: Mohammad S Anwar
# You are given a set of integers.
#
diff --git a/challenge-157/paulo-custodio/perl/ch-2.pl b/challenge-157/paulo-custodio/perl/ch-2.pl
index 2c298e11a7..48af9d0de7 100644
--- a/challenge-157/paulo-custodio/perl/ch-2.pl
+++ b/challenge-157/paulo-custodio/perl/ch-2.pl
@@ -2,7 +2,7 @@
# Challenge 157
#
-# TASK #2 › Brazilian Number
+# TASK #2 > Brazilian Number
# Submitted by: Mohammad S Anwar
# You are given a number $n > 3.
#
diff --git a/challenge-157/paulo-custodio/python/ch-1.py b/challenge-157/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..726edff089
--- /dev/null
+++ b/challenge-157/paulo-custodio/python/ch-1.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+
+# Challenge 157
+#
+# TASK #1 > Pythagorean Means
+# Submitted by: Mohammad S Anwar
+# You are given a set of integers.
+#
+# Write a script to compute all three Pythagorean Means i.e Arithmetic Mean,
+# Geometric Mean and Harmonic Mean of the given set of integers. Please refer
+# to wikipedia page for more informations.
+#
+# Example 1:
+# Input: @n = (1,3,5,6,9)
+# Output: AM = 4.8, GM = 3.8, HM = 2.8
+# CORRECTION [2022-03-21 16:35] GM = 3.9 (before)
+#
+# Example 2:
+# Input: @n = (2,4,6,8,10)
+# Output: AM = 6.0, GM = 5.2, HM = 4.4
+# Example 3:
+# Input: @n = (1,2,3,4,5)
+# Output: AM = 3.0, GM = 2.6, HM = 2.2
+
+import sys
+import numpy as np
+
+def am(n):
+ return np.sum(n) / len(n)
+
+def gm(n):
+ base = abs(np.prod(n))
+ exp = 1 / len(n)
+ return base ** exp
+
+def hm(n):
+ invn = [1/x for x in n]
+ return len(invn) / np.sum(invn)
+
+def f(n):
+ return f"{n:.1f}"
+
+n = list(map(float, sys.argv[1:]))
+if not n:
+ raise ValueError("Usage: ch-1.py n...")
+print(f"AM = {f(am(n))}, GM = {f(gm(n))}, HM = {f(hm(n))}")
diff --git a/challenge-157/paulo-custodio/python/ch-2.py b/challenge-157/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..9da6f097cb
--- /dev/null
+++ b/challenge-157/paulo-custodio/python/ch-2.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+
+# Challenge 157
+#
+# TASK #2 > Brazilian Number
+# Submitted by: Mohammad S Anwar
+# You are given a number $n > 3.
+#
+# Write a script to find out if the given number is a Brazilian Number.
+#
+# A positive integer number N has at least one natural number B where
+# 1 < B < N-1 where the representation of N in base B has same digits.
+#
+#
+# Example 1:
+# Input: $n = 7
+# Output: 1
+#
+# Since 7 in base 2 is 111.
+# Example 2:
+# Input: $n = 6
+# Output: 0
+#
+# Since 6 in base 2 is 110,
+# 6 in base 3 is 20 and
+# 6 in base 4 is 12.
+# Example 3:
+# Input: $n = 8
+# Output: 1
+#
+# Since 8 in base 3 is 22.
+
+import sys
+from math import log
+
+def cnv(n, base):
+ if n == 0:
+ return '0'
+ digits = []
+ while n:
+ digits.append(int(n % base))
+ n //= base
+ return ''.join(str(x) for x in digits[::-1])
+
+def is_brazilian(n):
+ for b in range(2, n - 1):
+ cnv_value = cnv(n, b)
+ if all(c == cnv_value[0] for c in cnv_value):
+ return True
+ return False
+
+n = int(sys.argv[1])
+print(1 if is_brazilian(n) else 0)
diff --git a/challenge-158/paulo-custodio/perl/ch-1.pl b/challenge-158/paulo-custodio/perl/ch-1.pl
index 1c23f8c0ff..c71f3fa9d0 100644
--- a/challenge-158/paulo-custodio/perl/ch-1.pl
+++ b/challenge-158/paulo-custodio/perl/ch-1.pl
@@ -2,7 +2,7 @@
# Challenge 158
#
-# TASK #1 › Additive Primes
+# TASK #1 > Additive Primes
# Submitted by: Mohammad S Anwar
# Write a script to find out all Additive Primes <= 100.
#
diff --git a/challenge-158/paulo-custodio/perl/ch-2.pl b/challenge-158/paulo-custodio/perl/ch-2.pl
index 8f28f63531..9d5cb05d83 100644
--- a/challenge-158/paulo-custodio/perl/ch-2.pl
+++ b/challenge-158/paulo-custodio/perl/ch-2.pl
@@ -2,7 +2,7 @@
# Challenge 158
#
-# TASK #2 › First Series Cuban Primes
+# TASK #2 > First Series Cuban Primes
# Submitted by: Mohammad S Anwar
# Write a script to compute first series Cuban Primes <= 1000. Please refer
# wikipedia page for more informations.
diff --git a/challenge-158/paulo-custodio/python/ch-1.py b/challenge-158/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..ad3b7825eb
--- /dev/null
+++ b/challenge-158/paulo-custodio/python/ch-1.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+# Challenge 158
+#
+# TASK #1 > Additive Primes
+# Submitted by: Mohammad S Anwar
+# Write a script to find out all Additive Primes <= 100.
+#
+# Additive primes are prime numbers for which the sum of their decimal digits
+# are also primes.
+#
+#
+# Output
+# 2, 3, 5, 7, 11, 23, 29, 41, 43, 47, 61, 67, 83, 89
+
+from sympy import isprime, nextprime
+
+def additive_primes(limit):
+ out = []
+ prime = 2
+ while prime < limit:
+ if isprime(sum(int(digit) for digit in str(prime))):
+ out.append(prime)
+ prime = nextprime(prime)
+ return out
+
+print(", ".join(map(str, additive_primes(100))))
diff --git a/challenge-158/paulo-custodio/python/ch-2.py b/challenge-158/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..1f7220d82b
--- /dev/null
+++ b/challenge-158/paulo-custodio/python/ch-2.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+# Challenge 158
+#
+# TASK #2 > First Series Cuban Primes
+# Submitted by: Mohammad S Anwar
+# Write a script to compute first series Cuban Primes <= 1000. Please refer
+# wikipedia page for more informations.
+#
+# Output
+# 7, 19, 37, 61, 127, 271, 331, 397, 547, 631, 919.
+#
+# p=(x^3-y^3)/(x-y), x=y+1, y>0
+# <=> p=3y^2+3y+1, y>0
+
+from sympy import isprime
+
+def cuban_primes(limit):
+ out = []
+ y = 1
+ p = 0
+ while True:
+ p = 3 * y * y + 3 * y + 1
+ if isprime(p):
+ out.append(p)
+ if p >= limit:
+ break
+ y += 1
+ return out
+
+print(", ".join(map(str, cuban_primes(1000))))
diff --git a/challenge-159/paulo-custodio/perl/ch-1.pl b/challenge-159/paulo-custodio/perl/ch-1.pl
index de8cf8b75c..4497c797be 100644
--- a/challenge-159/paulo-custodio/perl/ch-1.pl
+++ b/challenge-159/paulo-custodio/perl/ch-1.pl
@@ -2,7 +2,7 @@
# Challenge 159
#
-# TASK #1 › Farey Sequence
+# TASK #1 > Farey Sequence
# Submitted by: Mohammad S Anwar
# You are given a positive number, $n.
#
diff --git a/challenge-159/paulo-custodio/perl/ch-2.pl b/challenge-159/paulo-custodio/perl/ch-2.pl
index 0b8df98a0b..52a8efa892 100644
--- a/challenge-159/paulo-custodio/perl/ch-2.pl
+++ b/challenge-159/paulo-custodio/perl/ch-2.pl
@@ -2,7 +2,7 @@
# Challenge 159
#
-# TASK #2 › Moebius Number
+# TASK #2 > Moebius Number
# Submitted by: Mohammad S Anwar
# You are given a positive number $n.
#
diff --git a/challenge-159/paulo-custodio/python/ch-1.py b/challenge-159/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..70c306c5fa
--- /dev/null
+++ b/challenge-159/paulo-custodio/python/ch-1.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+# Challenge 159
+#
+# TASK #1 > Farey Sequence
+# Submitted by: Mohammad S Anwar
+# You are given a positive number, $n.
+#
+# Write a script to compute Farey Sequence of the order $n.
+#
+# Example 1:
+# Input: $n = 5
+# Output: 0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1.
+# Example 2:
+# Input: $n = 7
+# Output: 0/1, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 2/5, 3/7, 1/2, 4/7, 3/5, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 1/1.
+# Example 3:
+# Input: $n = 4
+# Output: 0/1, 1/4, 1/3, 1/2, 2/3, 3/4, 1/1.
+
+from math import gcd
+import sys
+
+def farey_sequence(n):
+ seq = [(0, 1), (1, 1)] # first and last terms
+
+ for i in range(1, n + 1):
+ for j in range(i + 1, n + 1):
+ if gcd(i, j) == 1:
+ seq.append((i, j))
+
+ seq.sort(key=lambda x: x[0] / x[1])
+ seq = [f"{num[0]}/{num[1]}" for num in seq]
+
+ return seq
+
+n = int(sys.argv[1])
+print(", ".join(farey_sequence(n)))
diff --git a/challenge-159/paulo-custodio/python/ch-2.py b/challenge-159/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..2ca571f2a1
--- /dev/null
+++ b/challenge-159/paulo-custodio/python/ch-2.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+# Challenge 159
+#
+# TASK #2 > Moebius Number
+# Submitted by: Mohammad S Anwar
+# You are given a positive number $n.
+#
+# Write a script to generate the Moebius Number for the given number.
+# Please refer to wikipedia page for more informations.
+#
+# Example 1:
+# Input: $n = 5
+# Output: -1
+# Example 2:
+# Input: $n = 10
+# Output: 1
+# Example 3:
+# Input: $n = 20
+# Output: 0
+
+from sympy.functions.combinatorial.numbers import mobius
+import sys
+
+n = int(sys.argv[1])
+print(mobius(n))
diff --git a/challenge-160/paulo-custodio/perl/ch-1.pl b/challenge-160/paulo-custodio/perl/ch-1.pl
index 958713a46a..db13fb71c3 100644
--- a/challenge-160/paulo-custodio/perl/ch-1.pl
+++ b/challenge-160/paulo-custodio/perl/ch-1.pl
@@ -2,12 +2,12 @@
# Challenge 160
#
-# TASK #1 › Four Is Magic
+# TASK #1 > Four Is Magic
# Submitted by: Mohammad S Anwar
# You are given a positive number, $n < 10.
#
# Write a script to generate english text sequence starting with the English
-# cardinal representation of the given number, the word ‘is’ and then the
+# cardinal representation of the given number, the word 'is' and then the
# English cardinal representation of the count of characters that made up the
# first word, followed by a comma. Continue until you reach four.
#
diff --git a/challenge-160/paulo-custodio/perl/ch-2.pl b/challenge-160/paulo-custodio/perl/ch-2.pl
index 9036422a55..e72e3c27f5 100644
--- a/challenge-160/paulo-custodio/perl/ch-2.pl
+++ b/challenge-160/paulo-custodio/perl/ch-2.pl
@@ -2,15 +2,15 @@