aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/eric-cheung/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-262/eric-cheung/python')
-rwxr-xr-xchallenge-262/eric-cheung/python/ch-1.py9
-rwxr-xr-xchallenge-262/eric-cheung/python/ch-2.py16
2 files changed, 25 insertions, 0 deletions
diff --git a/challenge-262/eric-cheung/python/ch-1.py b/challenge-262/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..c0148e39ce
--- /dev/null
+++ b/challenge-262/eric-cheung/python/ch-1.py
@@ -0,0 +1,9 @@
+
+## arrInt = [-3, 1, 2, -1, 3, -2, 4] ## Example 1
+## arrInt = [-1, -2, -3, 1] ## Example 2
+arrInt = [1, 2] ## Example 3
+
+arrPos = [nElem for nElem in arrInt if nElem > 0]
+arrNeg = [nElem for nElem in arrInt if nElem < 0]
+
+print (max(len(arrPos), len(arrNeg)))
diff --git a/challenge-262/eric-cheung/python/ch-2.py b/challenge-262/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..b5c88d67c4
--- /dev/null
+++ b/challenge-262/eric-cheung/python/ch-2.py
@@ -0,0 +1,16 @@
+
+from itertools import combinations
+
+## Example 1
+## arrInt = [3, 1, 2, 2, 2, 1, 3]
+## nK = 2
+
+## Example 2
+arrInt = [1, 2, 3]
+nK = 1
+
+arrCombList = combinations(range(len(arrInt)), 2)
+
+arrOutput = [arrIndxLoop for arrIndxLoop in list(arrCombList) if arrInt[arrIndxLoop[0]] == arrInt[arrIndxLoop[1]] and arrIndxLoop[0] * arrIndxLoop[1] % nK == 0]
+
+print (len(arrOutput))