diff options
Diffstat (limited to 'challenge-174/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-174/eric-cheung/python/ch-2.py | 32 |
1 files changed, 32 insertions, 0 deletions
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))
+
|
