From 21f3a3e3921adb1d855618833cd662471c588015 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Thu, 23 Dec 2021 19:42:36 +1100 Subject: sgreen solutions to challenge 144 --- challenge-144/sgreen/python/ch-1.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 challenge-144/sgreen/python/ch-1.py (limited to 'challenge-144/sgreen/python/ch-1.py') diff --git a/challenge-144/sgreen/python/ch-1.py b/challenge-144/sgreen/python/ch-1.py new file mode 100755 index 0000000000..0301f27de9 --- /dev/null +++ b/challenge-144/sgreen/python/ch-1.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +def get_primes(): + primes = [] + # Return a list of all primes between 2 and 50 (being 100 รท 2) + for i in range(2, 51): + for d in range(2, int(i / 2) + 1): + # If the number is divisable by something other than one and + # itself, it's not a prime + if i % d == 0: + break + else: + # It's a prime + primes.append(i) + + return primes + + +def main(): + primes = get_primes() + semiprimes = [] + + for i in primes: + for j in primes: + x = i * j + if x > 100: + break + if x not in semiprimes: + semiprimes.append(x) + + semiprimes.sort() + print(*semiprimes, sep=', ') + + +if __name__ == '__main__': + main() -- cgit