aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-17 18:11:59 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-17 18:11:59 +0000
commitbe0aa8f192058b000062863e21a1b42d71221898 (patch)
tree5338d4691e33024a4c5e14701545d002f3cd4f85
parent7a49fe037862e412389471f69ca4814083c863ca (diff)
downloadperlweeklychallenge-club-be0aa8f192058b000062863e21a1b42d71221898.tar.gz
perlweeklychallenge-club-be0aa8f192058b000062863e21a1b42d71221898.tar.bz2
perlweeklychallenge-club-be0aa8f192058b000062863e21a1b42d71221898.zip
- Added guest contributions by Eric Cheung.
-rwxr-xr-xchallenge-152/eric-cheung/excel-vba/Challenge_152.xlsmbin0 -> 27252 bytes
-rwxr-xr-xchallenge-152/eric-cheung/excel-vba/ch-1.bas36
-rwxr-xr-xchallenge-152/eric-cheung/excel-vba/ch-2.bas82
3 files changed, 118 insertions, 0 deletions
diff --git a/challenge-152/eric-cheung/excel-vba/Challenge_152.xlsm b/challenge-152/eric-cheung/excel-vba/Challenge_152.xlsm
new file mode 100755
index 0000000000..3e0b21d7d5
--- /dev/null
+++ b/challenge-152/eric-cheung/excel-vba/Challenge_152.xlsm
Binary files differ
diff --git a/challenge-152/eric-cheung/excel-vba/ch-1.bas b/challenge-152/eric-cheung/excel-vba/ch-1.bas
new file mode 100755
index 0000000000..9a8036b019
--- /dev/null
+++ b/challenge-152/eric-cheung/excel-vba/ch-1.bas
@@ -0,0 +1,36 @@
+Attribute VB_Name = "ModTask_01"
+Option Explicit
+
+Public Const strMyTitle As String = "Eric Cheung"
+
+Sub Task_01()
+
+ Dim nTriArr() As Variant
+ Dim nPathSum As Integer, nSubMin As Integer
+ Dim nLoop As Integer, nCount As Integer, nStep As Integer
+
+ '' nTriArr = Array(1, 5, 3, 2, 3, 4, 7, 1, 0, 2, 6, 4, 5, 2, 8) '' Example 1
+ nTriArr = Array(5, 2, 3, 4, 1, 5, 0, 1, 2, 3, 7, 2, 4, 1, 9) '' Example 2
+
+ nCount = 0
+ nStep = 1
+ nSubMin = 10000
+
+ For nLoop = LBound(nTriArr) To UBound(nTriArr)
+ nCount = nCount + 1
+ If nTriArr(nLoop) < nSubMin Then
+ nSubMin = nTriArr(nLoop)
+ End If
+
+ If nStep = nCount Then
+ nPathSum = nPathSum + nSubMin
+
+ nCount = 0
+ nStep = nStep + 1
+ nSubMin = 10000
+ End If
+ Next nLoop
+
+ MsgBox nPathSum, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-152/eric-cheung/excel-vba/ch-2.bas b/challenge-152/eric-cheung/excel-vba/ch-2.bas
new file mode 100755
index 0000000000..381eb2414c
--- /dev/null
+++ b/challenge-152/eric-cheung/excel-vba/ch-2.bas
@@ -0,0 +1,82 @@
+Attribute VB_Name = "ModTask_02"
+Option Explicit
+
+Function GetArea _
+( _
+ nLeftBtm_X As Integer, _
+ nLeftBtm_Y As Integer, _
+ nRightTop_X As Integer, _
+ nRightTop_Y As Integer _
+) As Integer
+ GetArea = (nRightTop_X - nLeftBtm_X) * (nRightTop_Y - nLeftBtm_Y)
+End Function
+
+Function GetLength _
+( _
+ nLeftBtm_01 As Integer, _
+ nTopRight_01 As Integer, _
+ nLeftBtm_02 As Integer, _
+ nTopRight_02 As Integer _
+) As Integer
+ If nTopRight_02 >= nTopRight_01 And nLeftBtm_02 >= nLeftBtm_01 Then
+ GetLength = nTopRight_01 - nLeftBtm_02
+ ElseIf nLeftBtm_02 >= nLeftBtm_01 Then
+ GetLength = nTopRight_02 - nLeftBtm_01
+ ElseIf nLeftBtm_01 <= nTopRight_02 And nLeftBtm_01 >= nLeftBtm_02 Then
+ GetLength = Application.Min(nTopRight_01, nTopRight_02) - nLeftBtm_01
+ Else
+ GetLength = 0
+ End If
+End Function
+
+Sub Task_02()
+
+ ''========== Example 1 ==========
+ ''========== Rectangle 1 ==========
+ Const nRec_01_LeftBtm_X As Integer = -1
+ Const nRec_01_LeftBtm_Y As Integer = 0
+
+ Const nRec_01_RightTop_X As Integer = 2
+ Const nRec_01_RightTop_Y As Integer = 2
+ ''========== Rectangle 1 ==========
+
+
+ ''========== Rectangle 2 ==========
+ Const nRec_02_LeftBtm_X As Integer = 0
+ Const nRec_02_LeftBtm_Y As Integer = -1
+
+ Const nRec_02_RightTop_X As Integer = 4
+ Const nRec_02_RightTop_Y As Integer = 4
+ ''========== Rectangle 2 ==========
+ ''========== Example 1 ==========
+
+'' ''========== Example 2 ==========
+'' ''========== Rectangle 1 ==========
+'' Const nRec_01_LeftBtm_X As Integer = -3
+'' Const nRec_01_LeftBtm_Y As Integer = -1
+''
+'' Const nRec_01_RightTop_X As Integer = 1
+'' Const nRec_01_RightTop_Y As Integer = 3
+'' ''========== Rectangle 1 ==========
+''
+''
+'' ''========== Rectangle 2 ==========
+'' Const nRec_02_LeftBtm_X As Integer = -1
+'' Const nRec_02_LeftBtm_Y As Integer = -3
+''
+'' Const nRec_02_RightTop_X As Integer = 2
+'' Const nRec_02_RightTop_Y As Integer = 2
+'' ''========== Rectangle 2 ==========
+'' ''========== Example 2 ==========
+
+ Dim nResult As Integer
+
+ nResult = _
+ GetArea(nRec_01_LeftBtm_X, nRec_01_LeftBtm_Y, nRec_01_RightTop_X, nRec_01_RightTop_Y) _
+ + GetArea(nRec_02_LeftBtm_X, nRec_02_LeftBtm_Y, nRec_02_RightTop_X, nRec_02_RightTop_Y) _
+ - GetLength(nRec_01_LeftBtm_X, nRec_01_RightTop_X, nRec_02_LeftBtm_X, nRec_02_RightTop_X) _
+ * GetLength(nRec_01_LeftBtm_Y, nRec_01_RightTop_Y, nRec_02_LeftBtm_Y, nRec_02_RightTop_Y)
+
+ MsgBox nResult, vbOKOnly, strMyTitle
+
+End Sub