aboutsummaryrefslogtreecommitdiff
path: root/challenge-214/eric-cheung/python
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-05-02 14:47:44 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-05-02 14:47:44 +0800
commitfb913ef4e973a29450b92ca89588e839bf6635f6 (patch)
tree94abff55c6006a2b0a4b1da93a5e661753e00fea /challenge-214/eric-cheung/python
parentefea8410c80647939ae587536a4f1f66dd2c3a4a (diff)
parent6cc2e38f43011f65d7deaf1e03cf55e4306a53e5 (diff)
downloadperlweeklychallenge-club-fb913ef4e973a29450b92ca89588e839bf6635f6.tar.gz
perlweeklychallenge-club-fb913ef4e973a29450b92ca89588e839bf6635f6.tar.bz2
perlweeklychallenge-club-fb913ef4e973a29450b92ca89588e839bf6635f6.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-214/eric-cheung/python')
-rwxr-xr-xchallenge-214/eric-cheung/python/ch-1.py12
-rwxr-xr-xchallenge-214/eric-cheung/python/ch-2.py11
2 files changed, 23 insertions, 0 deletions
diff --git a/challenge-214/eric-cheung/python/ch-1.py b/challenge-214/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..ea68026c42
--- /dev/null
+++ b/challenge-214/eric-cheung/python/ch-1.py
@@ -0,0 +1,12 @@
+
+arrInputScore = [1, 2, 4, 3, 5] ## Example 1
+## arrInputScore = [8, 5, 6, 7, 4] ## Example 2
+## arrInputScore = [3, 5, 4, 2] ## Example 3
+## arrInputScore = [2, 5, 2, 1, 7, 5, 1] ## Example 4
+
+arrUniqSortScore = list(set(arrInputScore))
+arrUniqSortScore = arrUniqSortScore[::-1]
+arrInterRank = [max(arrUniqSortScore.index(nElem), len([1 for nLoop in arrInputScore if nLoop > nElem])) for nElem in arrInputScore]
+arrOutputRank = ["G" if nElem == 0 else "S" if nElem == 1 else "B" if nElem == 2 else nElem + 1 for nElem in arrInterRank]
+
+print (arrOutputRank)
diff --git a/challenge-214/eric-cheung/python/ch-2.py b/challenge-214/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..323352eaf9
--- /dev/null
+++ b/challenge-214/eric-cheung/python/ch-2.py
@@ -0,0 +1,11 @@
+
+## arrNum = [2, 4, 3, 3, 3, 4, 5, 4, 2] ## Example 1
+## arrNum = [1, 2, 2, 2, 2, 1] ## Example 2
+## arrNum = [1] ## Example 3
+arrNum = [2, 2, 2, 1, 1, 2, 2, 2] ## Example 4
+
+arrUniq = list(set(arrNum))
+arrCount = [arrNum.count(nElem) for nElem in arrUniq]
+arrSQ = [nElem * nElem for nElem in arrCount]
+
+print (sum(arrSQ))