aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-19 12:37:37 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-19 12:37:37 +0100
commit04bc4ffdb504743ce6477368f70ddcff8f1c75f6 (patch)
treecc55aef3c1f51401ccc063c4010d5a84fe946ddd
parent1f473efe023fdf051250ed595ae68d64e0992a71 (diff)
downloadperlweeklychallenge-club-04bc4ffdb504743ce6477368f70ddcff8f1c75f6.tar.gz
perlweeklychallenge-club-04bc4ffdb504743ce6477368f70ddcff8f1c75f6.tar.bz2
perlweeklychallenge-club-04bc4ffdb504743ce6477368f70ddcff8f1c75f6.zip
- Added guest contributions by Eric Cheung.
-rwxr-xr-xchallenge-174/eric-cheung/python/ch-1.py32
-rwxr-xr-xchallenge-174/eric-cheung/python/ch-2.py32
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-174/eric-cheung/python/ch-1.py b/challenge-174/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..6c56148e57
--- /dev/null
+++ b/challenge-174/eric-cheung/python/ch-1.py
@@ -0,0 +1,32 @@
+
+##
+
+def IsDisariumNum (nInput):
+
+ strInput = str(nInput)
+ nCheckSum = 0
+
+ for nIndex in range(0, len(strInput)):
+ nCheckSum = nCheckSum + int(strInput[nIndex]) ** (nIndex + 1)
+
+ if nCheckSum == nInput:
+ return True
+
+ return False
+
+
+arrDisariumNum = []
+
+
+nLoop = 0
+while len(arrDisariumNum) < 19:
+
+ if IsDisariumNum(nLoop):
+ arrDisariumNum.append(nLoop)
+
+ nLoop = nLoop + 1
+
+
+print (arrDisariumNum)
+## Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 89, 135, 175, 518, 598, 1306, 1676, 2427, 2646798]
+
diff --git a/challenge-174/eric-cheung/python/ch-2.py b/challenge-174/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..c12e8cfbcb
--- /dev/null
+++ b/challenge-174/eric-cheung/python/ch-2.py
@@ -0,0 +1,32 @@
+
+## Remark
+## https://www.geeksforgeeks.org/permutation-and-combination-in-python/
+
+
+## A Python program to print all permutations using library function
+from itertools import permutations
+
+
+def getPermuArr(arrList):
+
+ return permutations(arrList)
+
+
+def permutation2rank(arrList, arrCheck):
+
+ arrPerm = getPermuArr(arrList)
+ return list(arrPerm).index(tuple(arrCheck))
+
+
+def rank2permutation(arrList, nIndex):
+
+ arrPerm = getPermuArr(arrList)
+ return list(list(arrPerm)[nIndex])
+
+
+arrInput = [0, 1, 2]
+arrFind = [1, 0, 2]
+
+print (permutation2rank(arrInput, arrFind))
+print (rank2permutation(arrInput, 1))
+