diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-04 21:53:56 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-04 21:53:56 +0000 |
| commit | cfb5851065ef019a1c2415bc376f255a8de11f58 (patch) | |
| tree | 12fe599e68d5461355f4b9dbc47d501f166388cd | |
| parent | be9adf85225f54b69c57547002fa92affcbe83b6 (diff) | |
| download | perlweeklychallenge-club-cfb5851065ef019a1c2415bc376f255a8de11f58.tar.gz perlweeklychallenge-club-cfb5851065ef019a1c2415bc376f255a8de11f58.tar.bz2 perlweeklychallenge-club-cfb5851065ef019a1c2415bc376f255a8de11f58.zip | |
- Added guest contributions by Eric Cheung.
| -rwxr-xr-x | challenge-146/eric-cheung/excel-vba/Challenge_146.xlsm | bin | 0 -> 32721 bytes | |||
| -rwxr-xr-x | challenge-146/eric-cheung/excel-vba/ch-1.bas | 47 | ||||
| -rwxr-xr-x | challenge-146/eric-cheung/excel-vba/ch-2.bas | 45 |
3 files changed, 92 insertions, 0 deletions
diff --git a/challenge-146/eric-cheung/excel-vba/Challenge_146.xlsm b/challenge-146/eric-cheung/excel-vba/Challenge_146.xlsm Binary files differnew file mode 100755 index 0000000000..c4e8ff0908 --- /dev/null +++ b/challenge-146/eric-cheung/excel-vba/Challenge_146.xlsm diff --git a/challenge-146/eric-cheung/excel-vba/ch-1.bas b/challenge-146/eric-cheung/excel-vba/ch-1.bas new file mode 100755 index 0000000000..d67a6d4137 --- /dev/null +++ b/challenge-146/eric-cheung/excel-vba/ch-1.bas @@ -0,0 +1,47 @@ +Attribute VB_Name = "ModTask_01"
+Option Explicit
+
+Public Const strMyTitle As String = "Eric Cheung"
+
+Option Base 1
+Public nPrimeArr() As Long
+
+Function IsPrime(nInput As Integer) As Boolean
+
+ Dim nNumLoop As Integer
+
+ For nNumLoop = LBound(nPrimeArr) To UBound(nPrimeArr)
+ If nInput Mod nPrimeArr(nNumLoop) = 0 Then
+ IsPrime = False
+ Exit Function
+ End If
+ Next nNumLoop
+
+ IsPrime = True
+
+End Function
+
+Sub Task_01()
+
+ Const nPrimeCntMax As Integer = 10001
+
+ Dim nLoop As Integer, nPrimeCnt As Integer
+
+ ReDim nPrimeArr(1 To 1)
+
+ nPrimeCnt = 1
+ nPrimeArr(1) = 2
+ nLoop = 3
+
+ Do While (nPrimeCnt < nPrimeCntMax)
+ If IsPrime(nLoop) Then
+ nPrimeCnt = nPrimeCnt + 1
+ ReDim Preserve nPrimeArr(1 To nPrimeCnt)
+ nPrimeArr(nPrimeCnt) = nLoop
+ End If
+ nLoop = nLoop + 1
+ Loop
+
+ MsgBox nPrimeArr(nPrimeCnt), vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-146/eric-cheung/excel-vba/ch-2.bas b/challenge-146/eric-cheung/excel-vba/ch-2.bas new file mode 100755 index 0000000000..aa7c7d16ca --- /dev/null +++ b/challenge-146/eric-cheung/excel-vba/ch-2.bas @@ -0,0 +1,45 @@ +Attribute VB_Name = "ModTask_02"
+Option Explicit
+
+Sub FindCuriousFractionTree(ByVal nNumerator As Integer, ByVal nDenominator As Integer, ByRef nParentNumerator As Integer, ByRef nParentDenominator As Integer)
+
+ If nNumerator > nDenominator Then
+ nParentNumerator = nNumerator - nDenominator
+ nParentDenominator = nDenominator
+ ElseIf nNumerator = nDenominator Then
+ nParentNumerator = nNumerator
+ nParentDenominator = nDenominator
+ Else
+ nParentNumerator = nNumerator
+ nParentDenominator = nDenominator - nNumerator
+ End If
+
+End Sub
+
+Sub Task_02()
+
+ ''Credit: https://gdaymath.com/lessons/fractions/5-3-a-curious-fraction-tree/
+
+ '' Example 1
+ '' Const nNumeratorInput As Integer = 3
+ '' Const nDenominatorInput As Integer = 5
+
+ '' Example 2
+ Const nNumeratorInput As Integer = 4
+ Const nDenominatorInput As Integer = 3
+
+ Dim strMsg As String
+ Dim nNumeratorInputParent As Integer, nDenominatorInputParent As Integer
+ Dim nNumeratorInputGrandParent As Integer, nDenominatorInputGrandParent As Integer
+
+ FindCuriousFractionTree nNumeratorInput, nDenominatorInput, nNumeratorInputParent, nDenominatorInputParent
+ FindCuriousFractionTree nNumeratorInputParent, nDenominatorInputParent, nNumeratorInputGrandParent, nDenominatorInputGrandParent
+
+ strMsg = "Parent: " & nNumeratorInputParent & " / " & nDenominatorInputParent
+ strMsg = strMsg & vbNewLine
+ strMsg = strMsg & "GrandParent: " & nNumeratorInputGrandParent & " / " & nDenominatorInputGrandParent
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
+
|
