diff options
Diffstat (limited to 'challenge-199/eric-cheung/python')
| -rwxr-xr-x | challenge-199/eric-cheung/python/ch-1.py | 20 | ||||
| -rwxr-xr-x | challenge-199/eric-cheung/python/ch-2.py | 25 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-199/eric-cheung/python/ch-1.py b/challenge-199/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..5227a2c7b1 --- /dev/null +++ b/challenge-199/eric-cheung/python/ch-1.py @@ -0,0 +1,20 @@ +
+from itertools import combinations
+
+def get_GoodPairs_List(arrInput):
+
+ arrGoodPairsList = []
+
+ nIndxTuple = combinations(range(0, len(arrInput)), 2)
+
+ for nIndxLoop_01, nIndxLoop_02 in list(nIndxTuple):
+ if arrInput[nIndxLoop_01] == arrInput[nIndxLoop_02]:
+ arrGoodPairsList.append([nIndxLoop_01, nIndxLoop_02])
+
+ return arrGoodPairsList
+
+## arrInputList = [1, 2, 3, 1, 1, 3] ## Example 1
+## arrInputList = [1, 2, 3] ## Example 2
+arrInputList = [1, 1, 1, 1] ## Example 3
+
+print (len(get_GoodPairs_List(arrInputList)))
diff --git a/challenge-199/eric-cheung/python/ch-2.py b/challenge-199/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..2ed1c89d29 --- /dev/null +++ b/challenge-199/eric-cheung/python/ch-2.py @@ -0,0 +1,25 @@ +
+from itertools import combinations
+
+def get_GoodTriplets_List(arrInput, arrInputInt):
+
+ arrGoodPairsList = []
+
+ nIndxTuple = combinations(range(0, len(arrInput)), 3)
+
+ for nIndxLoop_01, nIndxLoop_02, nIndxLoop_03 in list(nIndxTuple):
+ if abs(arrInput[nIndxLoop_01] - arrInput[nIndxLoop_02]) <= arrInputInt[0] and abs(arrInput[nIndxLoop_02] - arrInput[nIndxLoop_03]) <= arrInputInt[1] and abs(arrInput[nIndxLoop_01] - arrInput[nIndxLoop_03]) <= arrInputInt[2]:
+ arrGoodPairsList.append([nIndxLoop_01, nIndxLoop_02, nIndxLoop_03])
+
+ return arrGoodPairsList
+
+
+## Example 1
+## arrInputList = [3, 0, 1, 1, 9, 7]
+## arrInputList_Int = [7, 2, 3]
+
+## Example 2
+arrInputList = [1, 1, 2, 2, 3]
+arrInputList_Int = [0, 0, 1]
+
+print (len(get_GoodTriplets_List(arrInputList, arrInputList_Int)))
|
