diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
| commit | 72dc5412e640e26601ffdebc4f0247db4c4bc7fe (patch) | |
| tree | d405aa98925dfed0b745e5ec331e9498005b1de7 /challenge-243/eric-cheung/python | |
| parent | 35d79358f3d12607da66ffefefed5e93c469d396 (diff) | |
| parent | fda51162ad0e1e8b4489fd2c73ef7dfdc8f0df5e (diff) | |
| download | perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.gz perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.bz2 perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-243/eric-cheung/python')
| -rwxr-xr-x | challenge-243/eric-cheung/python/ch-1.py | 18 | ||||
| -rwxr-xr-x | challenge-243/eric-cheung/python/ch-2.py | 13 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-243/eric-cheung/python/ch-1.py b/challenge-243/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..9ee2534f4b --- /dev/null +++ b/challenge-243/eric-cheung/python/ch-1.py @@ -0,0 +1,18 @@ +
+from itertools import combinations
+
+def IsReversePair (arrInput):
+ if arrInput[0] > 2 * arrInput[1]:
+ return True
+ return False
+
+
+## arrNum = [1, 3, 2, 3, 1] ## Example 1
+arrNum = [2, 4, 3, 5, 1] ## Example 2
+
+
+arrCombList = combinations(arrNum, 2)
+arrOutputList = [arrLoop for arrLoop in list(arrCombList) if IsReversePair(arrLoop)]
+
+
+print (len(arrOutputList))
diff --git a/challenge-243/eric-cheung/python/ch-2.py b/challenge-243/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..8d186c9bf5 --- /dev/null +++ b/challenge-243/eric-cheung/python/ch-2.py @@ -0,0 +1,13 @@ +
+from itertools import combinations
+
+def GetFloorSum (arrInput):
+ return int(arrInput[0] / arrInput[1]) + int(arrInput[1] / arrInput[0])
+
+## arrNum = [2, 5, 9] ## Example 1
+arrNum = [7, 7, 7, 7, 7, 7, 7] ## Example 2
+
+arrCombList = combinations(arrNum, 2)
+nSum = len(arrNum) + sum([GetFloorSum(arrLoop) for arrLoop in list(arrCombList)])
+
+print (nSum)
|
