diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-12-23 13:20:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-23 13:20:06 +0000 |
| commit | a8bb8b3321e3967103e48cdbe331c49034fc5c04 (patch) | |
| tree | 3fb18e073f68658cf9b01438b14f7315f52f9925 /challenge-144/sgreen/python/ch-1.py | |
| parent | 0b6f4d54af679d89fa396863f0a774a35f719a8c (diff) | |
| parent | 21f3a3e3921adb1d855618833cd662471c588015 (diff) | |
| download | perlweeklychallenge-club-a8bb8b3321e3967103e48cdbe331c49034fc5c04.tar.gz perlweeklychallenge-club-a8bb8b3321e3967103e48cdbe331c49034fc5c04.tar.bz2 perlweeklychallenge-club-a8bb8b3321e3967103e48cdbe331c49034fc5c04.zip | |
Merge pull request #5405 from simongreen-net/master
sgreen solutions to challenge 144
Diffstat (limited to 'challenge-144/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-144/sgreen/python/ch-1.py | 36 |
1 files changed, 36 insertions, 0 deletions
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() |
