diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-16 13:09:03 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-16 13:09:03 +0000 |
| commit | 391d1da79411c0645140c4cacc15a23c51a1f928 (patch) | |
| tree | 60202485d23b46e31ea142a3afc51adbf4de289e | |
| parent | f2108bcfd8d40bd168834463da23cf5575649048 (diff) | |
| download | perlweeklychallenge-club-391d1da79411c0645140c4cacc15a23c51a1f928.tar.gz perlweeklychallenge-club-391d1da79411c0645140c4cacc15a23c51a1f928.tar.bz2 perlweeklychallenge-club-391d1da79411c0645140c4cacc15a23c51a1f928.zip | |
- Added guest contributions by Eric Cheung.
| -rwxr-xr-x | challenge-139/eric-cheung/excel-vba/Challenge_139.xlsm | bin | 0 -> 35559 bytes | |||
| -rwxr-xr-x | challenge-139/eric-cheung/excel-vba/ch-1.bas | 41 | ||||
| -rwxr-xr-x | challenge-139/eric-cheung/excel-vba/ch-2.bas | 70 |
3 files changed, 111 insertions, 0 deletions
diff --git a/challenge-139/eric-cheung/excel-vba/Challenge_139.xlsm b/challenge-139/eric-cheung/excel-vba/Challenge_139.xlsm Binary files differnew file mode 100755 index 0000000000..a30255edca --- /dev/null +++ b/challenge-139/eric-cheung/excel-vba/Challenge_139.xlsm diff --git a/challenge-139/eric-cheung/excel-vba/ch-1.bas b/challenge-139/eric-cheung/excel-vba/ch-1.bas new file mode 100755 index 0000000000..4b118d5d91 --- /dev/null +++ b/challenge-139/eric-cheung/excel-vba/ch-1.bas @@ -0,0 +1,41 @@ +Attribute VB_Name = "ModTask_01"
+Option Explicit
+
+Public Const strMyTitle As String = "Eric Cheung"
+
+Sub Task_01()
+
+ Dim strMsg As String
+ Dim nArr() As Variant
+ Dim nLoop As Integer
+ Dim bSortFlag As Boolean, bAscOrder As Boolean
+
+ bSortFlag = True
+
+ '' nArr = Array(1, 2, 3, 4, 5) '' Example 1
+ nArr = Array(1, 3, 2, 4, 5) '' Example 2
+
+ If nArr(LBound(nArr)) < nArr(LBound(nArr) + 1) Then
+ bAscOrder = True
+ Else
+ bAscOrder = False
+ End If
+
+ For nLoop = LBound(nArr) + 1 To UBound(nArr)
+ If _
+ bAscOrder And nArr(nLoop) < nArr(nLoop - 1) _
+ Or Not bAscOrder And nArr(nLoop) > nArr(nLoop - 1) _
+ Then
+ bSortFlag = False
+ Exit For
+ End If
+ Next nLoop
+
+ strMsg = "0"
+ If bSortFlag Then
+ strMsg = "1"
+ End If
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-139/eric-cheung/excel-vba/ch-2.bas b/challenge-139/eric-cheung/excel-vba/ch-2.bas new file mode 100755 index 0000000000..1262f0557b --- /dev/null +++ b/challenge-139/eric-cheung/excel-vba/ch-2.bas @@ -0,0 +1,70 @@ +Attribute VB_Name = "ModTask_02"
+Option Explicit
+
+Function IsPrime(nInput As Integer) As Boolean
+
+ Dim nLoop As Integer
+
+ For nLoop = 2 To Int(Sqr(nInput))
+ If nInput Mod nLoop = 0 Then
+ IsPrime = False
+ Exit Function
+ End If
+ Next nLoop
+
+ IsPrime = True
+
+End Function
+
+Function FindPeriodPrime(nInput As Integer) As Integer
+
+ Dim nTemp As Integer, nSubTemp As Integer, nLoop As Integer
+
+ FindPeriodPrime = 0
+ nTemp = 1
+
+ For nLoop = 1 To nInput - 1
+ nTemp = (10 * nTemp) Mod nInput
+ Next nLoop
+
+ nSubTemp = nTemp
+
+ Do
+ nTemp = (10 * nTemp) Mod nInput
+ FindPeriodPrime = FindPeriodPrime + 1
+ Loop While nSubTemp <> nTemp
+
+End Function
+
+Sub Task_02()
+
+ '' Credit: https://rosettacode.org/wiki/Long_primes#Java
+
+ Const nLongPrimeMaxCount As Integer = 5
+
+ Dim strMsg As String
+ Dim nLongPrimeLoopCnt As Integer
+ Dim nPrimeLoop As Integer
+
+ nLongPrimeLoopCnt = 0
+ nPrimeLoop = 7 '' First Long Prime Number
+
+ Do
+ If IsPrime(nPrimeLoop) Then
+ If FindPeriodPrime(nPrimeLoop) = nPrimeLoop - 1 Then
+ If strMsg <> "" Then
+ strMsg = strMsg & ", "
+ End If
+ strMsg = strMsg & nPrimeLoop
+ nLongPrimeLoopCnt = nLongPrimeLoopCnt + 1
+ End If
+ End If
+
+ nPrimeLoop = nPrimeLoop + 2
+ Loop While nLongPrimeLoopCnt < nLongPrimeMaxCount
+
+ strMsg = "First " & nLongPrimeMaxCount & " Long Primes are: " & strMsg
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
|
