diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-08-31 17:06:23 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-08-31 17:06:23 +0100 |
| commit | 7579d184412cc66d8a2a4ad096e5c8dda0a477db (patch) | |
| tree | 9fdaaffb8dfd06b3a06458aa13c405e1b1007aba | |
| parent | d394022d148f778f6e093af9b593d0e6ec5fd1eb (diff) | |
| download | perlweeklychallenge-club-7579d184412cc66d8a2a4ad096e5c8dda0a477db.tar.gz perlweeklychallenge-club-7579d184412cc66d8a2a4ad096e5c8dda0a477db.tar.bz2 perlweeklychallenge-club-7579d184412cc66d8a2a4ad096e5c8dda0a477db.zip | |
- Added guest contributions by Eric Cheung.
| -rwxr-xr-x | challenge-128/eric-cheung/excel-vba/Challenge_128.xlsm | bin | 0 -> 34597 bytes | |||
| -rwxr-xr-x | challenge-128/eric-cheung/excel-vba/ch-1.bas | 82 | ||||
| -rwxr-xr-x | challenge-128/eric-cheung/excel-vba/ch-2.bas | 54 |
3 files changed, 136 insertions, 0 deletions
diff --git a/challenge-128/eric-cheung/excel-vba/Challenge_128.xlsm b/challenge-128/eric-cheung/excel-vba/Challenge_128.xlsm Binary files differnew file mode 100755 index 0000000000..b33d8f616e --- /dev/null +++ b/challenge-128/eric-cheung/excel-vba/Challenge_128.xlsm diff --git a/challenge-128/eric-cheung/excel-vba/ch-1.bas b/challenge-128/eric-cheung/excel-vba/ch-1.bas new file mode 100755 index 0000000000..f44af35acc --- /dev/null +++ b/challenge-128/eric-cheung/excel-vba/ch-1.bas @@ -0,0 +1,82 @@ +Attribute VB_Name = "ModTask_01"
+Option Explicit
+Option Base 1
+Public Const strMyTitle As String = "Eric Cheung"
+
+''Public Const nRowNum As Integer = 3
+''Public Const nColNum As Integer = 6
+
+Public Const nRowNum As Integer = 3
+Public Const nColNum As Integer = 4
+
+Function bIsMatrixOne _
+( _
+ ByRef nMatrix, _
+ nStartRowIndx As Integer, _
+ nStartColIndx As Integer, _
+ nEndRowIndx As Integer, _
+ nEndColIndx As Integer _
+) As Boolean
+
+ Dim nRowSubLoop As Integer, nColSubLoop As Integer
+ bIsMatrixOne = False
+
+ For nRowSubLoop = nStartRowIndx To nEndRowIndx
+ For nColSubLoop = nStartColIndx To nEndColIndx
+ If nMatrix(nRowSubLoop, nColSubLoop) = 1 Then
+ bIsMatrixOne = True
+ Exit Function
+ End If
+ Next nColSubLoop
+ Next nRowSubLoop
+
+End Function
+
+Sub Task_01()
+
+ Dim nBinArr(1 To nRowNum, 1 To nColNum) As Integer
+ Dim nRowLoop As Integer, nColLoop As Integer, nRowNestLoop As Integer, nColNestLoop As Integer
+ Dim nRowZeroMax As Integer, nColZeroMax As Integer
+ Dim nTempRowNum As Integer, nTempColNum As Integer
+ Dim strMsg As String
+
+ 'Initialize
+'' nBinArr(1, 1) = 1: nBinArr(1, 2) = 0: nBinArr(1, 3) = 0: nBinArr(1, 4) = 0: nBinArr(1, 3) = 1: nBinArr(1, 6) = 0
+'' nBinArr(2, 1) = 1: nBinArr(2, 2) = 1: nBinArr(2, 3) = 0: nBinArr(2, 4) = 0: nBinArr(2, 3) = 0: nBinArr(2, 6) = 1
+'' nBinArr(3, 1) = 1: nBinArr(3, 2) = 0: nBinArr(3, 3) = 0: nBinArr(3, 4) = 0: nBinArr(3, 3) = 0: nBinArr(3, 6) = 0
+
+ nBinArr(1, 1) = 0: nBinArr(1, 2) = 0: nBinArr(1, 3) = 1: nBinArr(1, 4) = 1
+ nBinArr(2, 1) = 0: nBinArr(2, 2) = 0: nBinArr(2, 3) = 0: nBinArr(2, 4) = 1
+ nBinArr(3, 1) = 0: nBinArr(3, 2) = 0: nBinArr(3, 3) = 1: nBinArr(3, 4) = 0
+
+ If Application.Sum(nBinArr) = nRowNum * nColNum Then
+ 'All 1
+ nRowZeroMax = 0: nColZeroMax = 0
+ Else
+ nRowZeroMax = 1: nColZeroMax = 1
+
+ For nRowLoop = 1 To nRowNum
+ For nColLoop = 1 To nColNum
+ If nBinArr(nRowLoop, nColLoop) = 0 Then
+ For nRowNestLoop = nRowLoop + 1 To nRowNum
+ For nColNestLoop = nColLoop + 1 To nColNum
+ If Not bIsMatrixOne(nBinArr, nRowLoop, nColLoop, nRowNestLoop, nColNestLoop) Then
+ nTempRowNum = nRowNestLoop - nRowLoop + 1
+ nTempColNum = nColNestLoop - nColLoop + 1
+ If nTempRowNum * nTempColNum > nRowZeroMax * nColZeroMax Then
+ nRowZeroMax = nTempRowNum
+ nColZeroMax = nTempColNum
+ End If
+ End If
+ Next nColNestLoop
+ Next nRowNestLoop
+ End If
+ Next nColLoop
+ Next nRowLoop
+ End If
+
+ strMsg = "Max. SubMatrix having only : " & nRowZeroMax & " * " & nColZeroMax
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-128/eric-cheung/excel-vba/ch-2.bas b/challenge-128/eric-cheung/excel-vba/ch-2.bas new file mode 100755 index 0000000000..9245ab3cee --- /dev/null +++ b/challenge-128/eric-cheung/excel-vba/ch-2.bas @@ -0,0 +1,54 @@ +Attribute VB_Name = "ModTask_02"
+Option Explicit
+Option Base 1
+
+Sub Task_02()
+
+ ''Const nTrainNum As Integer = 2
+ Const nTrainNum As Integer = 6
+
+ Dim strArrivalArr(1 To nTrainNum) As String, strDepartArr(1 To nTrainNum) As String
+ Dim strPlatFormDepart() As String, nPlatFormNum As Integer
+ Dim nLoop As Integer, nSubLoop As Integer, nTemp As Integer
+ Dim strMsg As String
+
+ ReDim strPlatFormDepart(1 To 1)
+
+ 'Initialize
+'' strArrivalArr(1) = "11:20": strArrivalArr(2) = "14:30"
+'' strDepartArr(1) = "11:50": strDepartArr(2) = "15:00"
+
+ strArrivalArr(1) = "10:20": strArrivalArr(2) = "11:00": strArrivalArr(3) = "11:10": strArrivalArr(4) = "12:20": strArrivalArr(5) = "16:20": strArrivalArr(6) = "19:00"
+ strDepartArr(1) = "10:30": strDepartArr(2) = "13:20": strDepartArr(3) = "12:40": strDepartArr(4) = "12:50": strDepartArr(5) = "20:20": strDepartArr(6) = "21:20"
+
+ nPlatFormNum = 1
+
+ If nTrainNum > 1 Then
+ For nLoop = 1 To nTrainNum
+ If nLoop > 1 Then
+ nTemp = nPlatFormNum
+ For nSubLoop = 1 To nPlatFormNum
+ If strArrivalArr(nLoop) < strPlatFormDepart(nSubLoop) Then
+ nTemp = nTemp - 1
+ Else
+ strPlatFormDepart(nSubLoop) = strDepartArr(nLoop)
+ Exit For
+ End If
+ Next nSubLoop
+ If nTemp = 0 Then
+ nPlatFormNum = nPlatFormNum + 1
+ ReDim Preserve strPlatFormDepart(1 To nPlatFormNum)
+ strPlatFormDepart(nPlatFormNum) = strDepartArr(nLoop)
+ End If
+ Else
+ strPlatFormDepart(nLoop) = strDepartArr(nLoop)
+ End If
+ Next nLoop
+ End If
+
+ strMsg = "Minimum " & nPlatFormNum & " platform(s) is/are needed"
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
+
|
