aboutsummaryrefslogtreecommitdiff
path: root/challenge-169/michael-dicicco/python/ch-1.py
diff options
context:
space:
mode:
authorRyan Thompson <rjt-pl@users.noreply.github.com>2022-06-16 17:10:46 -0600
committerGitHub <noreply@github.com>2022-06-16 17:10:46 -0600
commitc92803076d8d8f9fee7bb945e0e268399e32cdd3 (patch)
treef59a55e4a378f42fa80a5b6f13238b12088e7d4b /challenge-169/michael-dicicco/python/ch-1.py
parent40198d275c123f30a185aea4da69f2c3b9424dab (diff)
parent7c2fa584618da574d42b1713c3c343423991c781 (diff)
downloadperlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.tar.gz
perlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.tar.bz2
perlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-169/michael-dicicco/python/ch-1.py')
-rw-r--r--challenge-169/michael-dicicco/python/ch-1.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-169/michael-dicicco/python/ch-1.py b/challenge-169/michael-dicicco/python/ch-1.py
new file mode 100644
index 0000000000..102d3eaeb5
--- /dev/null
+++ b/challenge-169/michael-dicicco/python/ch-1.py
@@ -0,0 +1,24 @@
+def is_brilliant(factors):
+ """a brilliant number has only two prime factors of the same length"""
+ return len(factors) == 2 and len(str(int(factors[0]))) == len(str(int(factors[1])))
+
+
+def prime_factors(n):
+ output = []
+
+ while n % 2 == 0:
+ output.append(2)
+ n /= 2
+
+ for i in range(3, int(n ** 1 / 2 + 1), 2):
+ while n % i == 0:
+ output.append(i)
+ n /= i
+
+ if n > 2:
+ output.append(int(n))
+ return output
+
+
+if __name__ == '__main__':
+ print(", ".join([str(i) for i in range(4, 300) if is_brilliant(prime_factors(i))]))