aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-09 23:24:05 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-09 23:24:05 +0100
commitcced4df12336d27ff6b3186c66fece1deb6fa9bd (patch)
tree6e2c79b36feecc502346b5f902ffd6a3ac96d643
parentbcddf4193dc2622c821d3457534af8e20f01f3f4 (diff)
downloadperlweeklychallenge-club-cced4df12336d27ff6b3186c66fece1deb6fa9bd.tar.gz
perlweeklychallenge-club-cced4df12336d27ff6b3186c66fece1deb6fa9bd.tar.bz2
perlweeklychallenge-club-cced4df12336d27ff6b3186c66fece1deb6fa9bd.zip
- Added guest contributions by Laurent Rosenfeld.
-rw-r--r--challenge-172/laurent-rosenfeld/julia/ch-1.jl12
-rw-r--r--challenge-172/laurent-rosenfeld/julia/ch-2.jl11
-rw-r--r--challenge-172/laurent-rosenfeld/python/ch-1.py25
-rw-r--r--challenge-172/laurent-rosenfeld/python/ch-2.py17
4 files changed, 65 insertions, 0 deletions
diff --git a/challenge-172/laurent-rosenfeld/julia/ch-1.jl b/challenge-172/laurent-rosenfeld/julia/ch-1.jl
new file mode 100644
index 0000000000..c2f8beea4d
--- /dev/null
+++ b/challenge-172/laurent-rosenfeld/julia/ch-1.jl
@@ -0,0 +1,12 @@
+using Primes
+using Combinatorics
+
+function partition(m, n)
+ for comb in combinations(primes(m),n)
+ sum(comb) == m && println("$m $n: ", comb)
+ end
+end
+
+partition(18,2)
+partition(19, 3)
+partition(25, 2)
diff --git a/challenge-172/laurent-rosenfeld/julia/ch-2.jl b/challenge-172/laurent-rosenfeld/julia/ch-2.jl
new file mode 100644
index 0000000000..2a04e505ca
--- /dev/null
+++ b/challenge-172/laurent-rosenfeld/julia/ch-2.jl
@@ -0,0 +1,11 @@
+using Statistics
+
+moons = sort([0, 0, 1, 2, 63, 61, 27, 13])
+
+min = moons[1] # Julia indices start at 1
+first_quart = quantile(moons, 0.25)
+median = quantile(moons, 0.5)
+third_quart = quantile(moons, 0.75)
+max = last(moons)
+
+println("Min: $min; First quartile = $first_quart; Median: $median; Third quartile: $third_quart; Max: $max")
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));