From c99d4e2e180ac519c405e7bb7f799eb479aa0cea Mon Sep 17 00:00:00 2001 From: mddicicco Date: Wed, 15 Jun 2022 14:27:54 -0500 Subject: java and python solutions --- challenge-169/michael-dicicco/python/ch-1.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 challenge-169/michael-dicicco/python/ch-1.py (limited to 'challenge-169/michael-dicicco/python/ch-1.py') 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))])) -- cgit