diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-09 23:24:05 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-09 23:24:05 +0100 |
| commit | cced4df12336d27ff6b3186c66fece1deb6fa9bd (patch) | |
| tree | 6e2c79b36feecc502346b5f902ffd6a3ac96d643 /challenge-172/laurent-rosenfeld/python/ch-1.py | |
| parent | bcddf4193dc2622c821d3457534af8e20f01f3f4 (diff) | |
| download | perlweeklychallenge-club-cced4df12336d27ff6b3186c66fece1deb6fa9bd.tar.gz perlweeklychallenge-club-cced4df12336d27ff6b3186c66fece1deb6fa9bd.tar.bz2 perlweeklychallenge-club-cced4df12336d27ff6b3186c66fece1deb6fa9bd.zip | |
- Added guest contributions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-172/laurent-rosenfeld/python/ch-1.py')
| -rw-r--r-- | challenge-172/laurent-rosenfeld/python/ch-1.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-172/laurent-rosenfeld/python/ch-1.py b/challenge-172/laurent-rosenfeld/python/ch-1.py new file mode 100644 index 0000000000..098213199f --- /dev/null +++ b/challenge-172/laurent-rosenfeld/python/ch-1.py @@ -0,0 +1,25 @@ +import math +from itertools import combinations + +def is_prime(n): + if n == 2: + return True + if n == 0 or n == 1 or n % 2 == 0: + return False + p = 3 + sqrt_n = math.sqrt(n) + while (p <= sqrt_n): + if ((n % p) == 0): + return False + p += 2 + return True + +def partition(m, n): + primes = filter(is_prime, range (1, m)) + for combination in combinations(primes, n): + if sum(combination) == m: + print(m, n, ": ", combination) + +partition(18, 2) +partition(19, 3) +partition(25, 2) |
