aboutsummaryrefslogtreecommitdiff
path: root/challenge-172/eric-cheung/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-172/eric-cheung/python')
-rwxr-xr-xchallenge-172/eric-cheung/python/ch-1.py46
-rwxr-xr-xchallenge-172/eric-cheung/python/ch-2.py13
2 files changed, 59 insertions, 0 deletions
diff --git a/challenge-172/eric-cheung/python/ch-1.py b/challenge-172/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..7ef1bf9218
--- /dev/null
+++ b/challenge-172/eric-cheung/python/ch-1.py
@@ -0,0 +1,46 @@
+
+## Remarks
+## https://rosettacode.org/wiki/Partition_an_integer_x_into_n_primes#Python
+
+from itertools import combinations as cmb
+
+def IsPrime(nInput):
+
+ if nInput == 2:
+ return True
+
+ if nInput % 2 == 0:
+ return False
+
+ return all(nInput % xLoop > 0 for xLoop in range(3, int(nInput ** 0.5) + 1, 2))
+
+
+def genP(nInput):
+
+ pArr = [2]
+ pArr.extend([xLoop for xLoop in range(3, nInput + 1, 2) if IsPrime(xLoop)])
+
+ return pArr
+
+
+## dataArr = [(99809, 1), (18, 2), (19, 3), (20, 4), (2017, 24), (22699, 1), (22699, 2), (22699, 3), (22699, 4), (40355, 3)]
+dataArr = [(18, 2), (19, 3)]
+
+
+for nNum_01, nNum_02 in data:
+
+ nIter = iter(cmb(genP(nNum_01), nNum_02))
+
+ while True:
+ try:
+ nNextSum = next(nIter)
+ if sum(nNextSum) == nNum_01:
+
+ print (" ".join([repr((nNum_01, nNum_02)), "->", " + ".join(str(nSumLoop) for nSumLoop in nNextSum)]))
+ break
+
+ except StopIteration:
+
+ print (repr((nNum_01, nNum_02)) + " -> Not possible")
+ break
+
diff --git a/challenge-172/eric-cheung/python/ch-2.py b/challenge-172/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..f8d57158f5
--- /dev/null
+++ b/challenge-172/eric-cheung/python/ch-2.py
@@ -0,0 +1,13 @@
+
+## Remarks
+## https://en.wikipedia.org/wiki/Five-number_summary
+
+import numpy as np
+
+def getFiveNumSumm(arrData):
+
+ ## Five Number Summary
+ return np.percentile(arrData, [0, 25, 50, 75, 100], interpolation = "midpoint")
+
+arrInput = [0, 0, 1, 2, 63, 61, 27, 13]
+print (getFiveNumSumm(arrInput))