aboutsummaryrefslogtreecommitdiff
path: root/challenge-172/laurent-rosenfeld/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-172/laurent-rosenfeld/python')
-rw-r--r--challenge-172/laurent-rosenfeld/python/ch-1.py25
-rw-r--r--challenge-172/laurent-rosenfeld/python/ch-2.py17
2 files changed, 42 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)
diff --git a/challenge-172/laurent-rosenfeld/python/ch-2.py b/challenge-172/laurent-rosenfeld/python/ch-2.py
new file mode 100644
index 0000000000..f99c3098cb
--- /dev/null
+++ b/challenge-172/laurent-rosenfeld/python/ch-2.py
@@ -0,0 +1,17 @@
+def median(n):
+ c = len(n)
+ return n[int((c - 1) / 2)] if c % 2 != 0 else (n[int(c/2 -1)] + n[int(c/2)])/2
+
+
+def summary(input):
+ min = input[0]
+ max = input[-1]
+ med = median(input)
+ lower_half = list(filter(lambda p: p < med, input))
+ # print(lower_half)
+ first_quart = median(lower_half)
+ third_quart = median(list(filter(lambda p: p > med, input)))
+ return(min, first_quart, med, third_quart, max)
+
+moons = sorted([0, 0, 1, 2, 63, 61, 27, 13])
+print(summary(moons));