diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-18 19:26:32 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-18 19:26:32 +0000 |
| commit | 2832ab5bb6f979a6ce8b37c47250721c648d6542 (patch) | |
| tree | ea86d94e51d6d2679a0b7cc7633808c0c61cdc62 | |
| parent | 2d094b4129243b5c1f7bee902147de2bd7a79339 (diff) | |
| download | perlweeklychallenge-club-2832ab5bb6f979a6ce8b37c47250721c648d6542.tar.gz perlweeklychallenge-club-2832ab5bb6f979a6ce8b37c47250721c648d6542.tar.bz2 perlweeklychallenge-club-2832ab5bb6f979a6ce8b37c47250721c648d6542.zip | |
- Added guest contributions by Eric Cheung.
| -rwxr-xr-x | challenge-148/eric-cheung/excel-vba/Challenge_148.xlsm | bin | 0 -> 26830 bytes | |||
| -rwxr-xr-x | challenge-148/eric-cheung/excel-vba/ch-1.bas | 131 | ||||
| -rwxr-xr-x | challenge-148/eric-cheung/python/ch-2.py | 44 |
3 files changed, 175 insertions, 0 deletions
diff --git a/challenge-148/eric-cheung/excel-vba/Challenge_148.xlsm b/challenge-148/eric-cheung/excel-vba/Challenge_148.xlsm Binary files differnew file mode 100755 index 0000000000..04b2bf80f2 --- /dev/null +++ b/challenge-148/eric-cheung/excel-vba/Challenge_148.xlsm diff --git a/challenge-148/eric-cheung/excel-vba/ch-1.bas b/challenge-148/eric-cheung/excel-vba/ch-1.bas new file mode 100755 index 0000000000..230fb4f7d5 --- /dev/null +++ b/challenge-148/eric-cheung/excel-vba/ch-1.bas @@ -0,0 +1,131 @@ +Attribute VB_Name = "ModTask_01"
+Option Explicit
+
+Public Const strMyTitle As String = "Eric Cheung"
+
+Function ConvUnitDigitToWord(ByVal nUnitDigit As Integer) As String
+
+ Select Case nUnitDigit
+ Case 1
+ ConvUnitDigitToWord = "One"
+ Case 2
+ ConvUnitDigitToWord = "Two"
+ Case 3
+ ConvUnitDigitToWord = "Three"
+ Case 4
+ ConvUnitDigitToWord = "Four"
+ Case 5
+ ConvUnitDigitToWord = "Five"
+ Case 6
+ ConvUnitDigitToWord = "Six"
+ Case 7
+ ConvUnitDigitToWord = "Seven"
+ Case 8
+ ConvUnitDigitToWord = "Eight"
+ Case 9
+ ConvUnitDigitToWord = "Nine"
+ End Select
+
+End Function
+
+Function ConvElevenToNineteenWord(ByVal nInput As Integer) As String
+
+ Select Case nInput
+ Case 11
+ ConvElevenToNineteenWord = "Eleven"
+ Case 12
+ ConvElevenToNineteenWord = "Twelve"
+ Case 13
+ ConvElevenToNineteenWord = "Thirteen"
+ Case 14
+ ConvElevenToNineteenWord = "Forteen"
+ Case 15
+ ConvElevenToNineteenWord = "Fifteen"
+ Case 16
+ ConvElevenToNineteenWord = "Sixteen"
+ Case 17
+ ConvElevenToNineteenWord = "Seventeen"
+ Case 18
+ ConvElevenToNineteenWord = "Eighteen"
+ Case 19
+ ConvElevenToNineteenWord = "Nineteen"
+ End Select
+
+End Function
+
+Function ConvTenDigitToWord(ByVal nTenDigit As Integer) As String
+
+ Select Case nTenDigit
+ Case 2
+ ConvTenDigitToWord = "Twenty"
+ Case 3
+ ConvTenDigitToWord = "Thirty"
+ Case 4
+ ConvTenDigitToWord = "Forty"
+ Case 5
+ ConvTenDigitToWord = "Fifty"
+ Case 6
+ ConvTenDigitToWord = "Sixty"
+ Case 7
+ ConvTenDigitToWord = "Seventy"
+ Case 8
+ ConvTenDigitToWord = "Eighty"
+ Case 9
+ ConvTenDigitToWord = "Ninety"
+ End Select
+
+End Function
+
+Function ConvNumToWord(ByVal nInput As Integer) As String
+
+ If nInput > 100 Then
+ ConvNumToWord = ""
+ Exit Function
+ End If
+
+ If nInput = 0 Then
+ ConvNumToWord = "Zero"
+ Exit Function
+ End If
+
+ If nInput < 0 Then
+ ConvNumToWord = ""
+ Exit Function
+ End If
+
+ If nInput = 100 Then
+ ConvNumToWord = "One Hundred"
+ ElseIf nInput < 10 Then
+ ConvNumToWord = ConvUnitDigitToWord(nInput)
+ ElseIf nInput = 10 Then
+ ConvNumToWord = "Ten"
+ ElseIf nInput < 20 Then
+ ConvNumToWord = ConvElevenToNineteenWord(nInput)
+ ElseIf nInput Mod 10 = 0 Then
+ ConvNumToWord = ConvTenDigitToWord(nInput / 10)
+ Else
+ ConvNumToWord = ConvTenDigitToWord(Int(nInput / 10)) & " " & ConvUnitDigitToWord(nInput Mod 10)
+ End If
+
+End Function
+
+Sub Task_01()
+
+ '' Remarks
+ '' https://en.wikipedia.org/wiki/Ban_number#:~:text=The%20first%20few%20eban%20numbers,in%20the%20sequence%20are%20even.
+
+ Dim strMsg As String
+ Dim nLoop As Integer
+
+ For nLoop = 1 To 100
+ If InStr(1, LCase(ConvNumToWord(nLoop)), "e") = 0 Then
+ If strMsg <> "" Then
+ strMsg = strMsg & ", "
+ End If
+ strMsg = strMsg & nLoop
+ End If
+ Next nLoop
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-148/eric-cheung/python/ch-2.py b/challenge-148/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..1e1311e7d4 --- /dev/null +++ b/challenge-148/eric-cheung/python/ch-2.py @@ -0,0 +1,44 @@ +## Credit:
+## https://theweeklychallenge.org/blog/perl-weekly-challenge-148/
+## https://github.com/Anshumanmahan/Cardano-Triplets/blob/master/CardanoTriplets.py
+## https://medium.com/swift-programming/cardano-triplets-in-swift-114692293795
+
+import math
+
+nCount = 0
+nCountMax = 5
+
+nNumMax = 200
+
+for nNum_01 in range(1, nNumMax):
+ for nNum_02 in range(1, nNumMax):
+ for nNum_03 in range(1, nNumMax):
+ x = nNum_01 - nNum_02 * math.sqrt(nNum_03)
+
+ if (x > 0):
+ y = math.pow(x, float(1) / 3)
+ else:
+ y = - math.pow(abs(x), float(1) / 3)
+
+ z = math.pow(nNum_01 + nNum_02 * math.sqrt(nNum_03), float(1) / 3.0) + y
+
+ ## Floating Point Rounding Errors
+ if (z > 0.999999 and z < 1.000001):
+ nCount = nCount + 1
+ print(nNum_01, nNum_02, nNum_03)
+
+ if (nCount == nCountMax):
+ break;
+
+ if (nCount == nCountMax):
+ break;
+
+ if (nCount == nCountMax):
+ break;
+
+## Results
+## 2 1 5
+## 5 1 52
+## 5 2 13
+## 8 1 189
+## 8 3 21
|
