From 04bc4ffdb504743ce6477368f70ddcff8f1c75f6 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 19 Jul 2022 12:37:37 +0100 Subject: - Added guest contributions by Eric Cheung. --- challenge-174/eric-cheung/python/ch-1.py | 32 ++++++++++++++++++++++++++++++++ challenge-174/eric-cheung/python/ch-2.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 challenge-174/eric-cheung/python/ch-1.py create mode 100755 challenge-174/eric-cheung/python/ch-2.py 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)) + -- cgit