diff options
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) |
