From 495113ce801fcfa3b0a8cdd8d276ae2f8c02612e Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 13 Dec 2021 12:47:07 +0000 Subject: - Added guest contributions by Eric Cheung. --- .../eric-cheung/excel-vba/Challenge_143.xlsm | Bin 0 -> 27321 bytes challenge-143/eric-cheung/excel-vba/ch-2.bas | 55 +++++++++++++++++++++ challenge-143/eric-cheung/python/ch-1.py | 9 ++++ 3 files changed, 64 insertions(+) create mode 100755 challenge-143/eric-cheung/excel-vba/Challenge_143.xlsm create mode 100755 challenge-143/eric-cheung/excel-vba/ch-2.bas create mode 100755 challenge-143/eric-cheung/python/ch-1.py diff --git a/challenge-143/eric-cheung/excel-vba/Challenge_143.xlsm b/challenge-143/eric-cheung/excel-vba/Challenge_143.xlsm new file mode 100755 index 0000000000..895a479b7d Binary files /dev/null and b/challenge-143/eric-cheung/excel-vba/Challenge_143.xlsm differ diff --git a/challenge-143/eric-cheung/excel-vba/ch-2.bas b/challenge-143/eric-cheung/excel-vba/ch-2.bas new file mode 100755 index 0000000000..101b9bea72 --- /dev/null +++ b/challenge-143/eric-cheung/excel-vba/ch-2.bas @@ -0,0 +1,55 @@ +Attribute VB_Name = "ModTask_02" +Option Explicit + +Public Const strMyTitle As String = "Eric Cheung" + +Sub Task_02() '' Stealthy Number + + '' Const nInpuNum As Integer = 36 '' Example 1 + '' Const nInpuNum As Integer = 12 '' Example 2 + Const nInpuNum As Integer = 6 '' Example 3 + + Dim nLoop As Integer, nSubLoop As Integer, nCnt As Integer + Dim bIsPrime As Boolean + + Dim nFactorArr_01() As Integer, nFactorArr_02() + + ReDim nFactorArr_01(1 To 1) + ReDim nFactorArr_02(1 To 1) + + nCnt = 1 + nFactorArr_01(1) = 1: nFactorArr_02(1) = nInpuNum + + bIsPrime = True + For nLoop = 2 To Sqr(nInpuNum) + If nInpuNum Mod nLoop = 0 Then + bIsPrime = False + + nCnt = nCnt + 1 + ReDim Preserve nFactorArr_01(1 To nCnt) + ReDim Preserve nFactorArr_02(1 To nCnt) + + nFactorArr_01(nCnt) = nLoop + nFactorArr_02(nCnt) = nInpuNum / nLoop + End If + Next nLoop + + If bIsPrime Then + MsgBox 0, vbOKOnly, strMyTitle + Exit Sub + End If + + For nLoop = LBound(nFactorArr_01) To UBound(nFactorArr_01) - 1 + For nSubLoop = nLoop + 1 To UBound(nFactorArr_01) + If Abs(nFactorArr_01(nLoop) + nFactorArr_02(nLoop) - nFactorArr_01(nSubLoop) - nFactorArr_02(nSubLoop)) = 1 Then + MsgBox 1, vbOKOnly, strMyTitle + Exit Sub + End If + Next nSubLoop + Next nLoop + + MsgBox 0, vbOKOnly, strMyTitle + +End Sub + + diff --git a/challenge-143/eric-cheung/python/ch-1.py b/challenge-143/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..4820b6c769 --- /dev/null +++ b/challenge-143/eric-cheung/python/ch-1.py @@ -0,0 +1,9 @@ +## Calculator +import os + +strMathExpr = "10 + 20 - 5" ## Example 1 +## strMathExpr = "(10 + 20 - 5) * 2" ## Example 2 + +print (strMathExpr + " = " + str(eval(strMathExpr))) + +os.system("pause") -- cgit