diff options
Diffstat (limited to 'challenge-171/eric-cheung/python')
| -rwxr-xr-x | challenge-171/eric-cheung/python/ch-1.py | 59 | ||||
| -rwxr-xr-x | challenge-171/eric-cheung/python/ch-2.py | 27 |
2 files changed, 86 insertions, 0 deletions
diff --git a/challenge-171/eric-cheung/python/ch-1.py b/challenge-171/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..46ddebdd00 --- /dev/null +++ b/challenge-171/eric-cheung/python/ch-1.py @@ -0,0 +1,59 @@ +## Remarks
+from math import sqrt
+
+## Code to Find all the Factors of the Number Excluding the Number itself
+def getFactors(nInput):
+
+ ## Vector to Store the Factors
+ vectArr = []
+ vectArr.append(1)
+
+ ## Note that this Loop runs till sqrt(nInput)
+ for nSubLoop in range(2, int(sqrt(nInput)) + 1, 1):
+ ## if the value of nSubLoop is a factor
+ if (nInput % nSubLoop == 0):
+ vectArr.append(nSubLoop);
+
+ ## Condition to Check the Divisor is not the Number itself
+ if (int(nInput / nSubLoop) != nSubLoop):
+ vectArr.append(int(nInput / nSubLoop))
+
+ ## Return the Vector
+ return vectArr
+
+## Function to check if the number is Abundant or not
+def checkAbundant(nInput):
+ nSum = 0
+
+ ## Find the Divisors Using Function
+ vec = getFactors(nInput)
+
+ ## nSum All the Factors
+ for nSubLoop in range(len(vec)):
+ nSum = nSum + vec[nSubLoop]
+
+ ## Check for Abundant or Not
+ if (nSum > nInput):
+ return True
+
+ return False
+
+
+## Driver Code
+if __name__ == '__main__':
+
+ nLoop = 11
+ nCount = 0
+ arrAbundantNum = []
+
+ while nCount < 20:
+
+ if checkAbundant(nLoop):
+ arrAbundantNum.append(nLoop)
+ nCount = nCount + 1
+
+ nLoop = nLoop + 2
+
+ print (arrAbundantNum)
+
+## [945, 1575, 2205, 2835, 3465, 4095, 4725, 5355, 5775, 5985, 6435, 6615, 6825, 7245, 7425, 7875, 8085, 8415, 8505, 8925]
diff --git a/challenge-171/eric-cheung/python/ch-2.py b/challenge-171/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..9d800fc25b --- /dev/null +++ b/challenge-171/eric-cheung/python/ch-2.py @@ -0,0 +1,27 @@ +
+## Remarks
+## https://www.geeksforgeeks.org/first-class-functions-python/
+## https://theweeklychallenge.org/blog/perl-weekly-challenge-171/
+
+
+## Python Program to illustrate Functions can be Passed as Arguments to Other Functions
+def getShout(strText):
+ return strText.upper()
+
+
+def getWhisper(strText):
+ return strText.lower()
+
+
+def getGreet(Func_1, Func_2):
+ ## f = Func_1
+ ## g = Func_2
+ ## getGreet = h = compose(f, g)
+ return Func_1(Func_2("Hi, I am created by a function passed as an argument."))
+
+
+## Driver Code
+if __name__ == '__main__':
+
+ print (getGreet(getShout, getWhisper))
+
|
