aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-08-13 00:21:00 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-08-13 00:21:00 +0100
commitb84b8e71bf81fec0d005905eedffb8633417e481 (patch)
tree99fedde5b0f6030d855de0b04cce24b4a5ac0368
parent8fbab7567f1c67a1956de87e83c35a786a539c10 (diff)
downloadperlweeklychallenge-club-b84b8e71bf81fec0d005905eedffb8633417e481.tar.gz
perlweeklychallenge-club-b84b8e71bf81fec0d005905eedffb8633417e481.tar.bz2
perlweeklychallenge-club-b84b8e71bf81fec0d005905eedffb8633417e481.zip
- Added guest contributions by Eric Cheung.
-rw-r--r--challenge-125/eric-cheung/excel-vba/Challenge_125.xlsmbin0 -> 33359 bytes
-rw-r--r--challenge-125/eric-cheung/excel-vba/ch-1.bas139
-rw-r--r--challenge-125/eric-cheung/python/ch-2.py66
3 files changed, 205 insertions, 0 deletions
diff --git a/challenge-125/eric-cheung/excel-vba/Challenge_125.xlsm b/challenge-125/eric-cheung/excel-vba/Challenge_125.xlsm
new file mode 100644
index 0000000000..d3e2f0be0c
--- /dev/null
+++ b/challenge-125/eric-cheung/excel-vba/Challenge_125.xlsm
Binary files differ
diff --git a/challenge-125/eric-cheung/excel-vba/ch-1.bas b/challenge-125/eric-cheung/excel-vba/ch-1.bas
new file mode 100644
index 0000000000..e31ee1dc56
--- /dev/null
+++ b/challenge-125/eric-cheung/excel-vba/ch-1.bas
@@ -0,0 +1,139 @@
+Attribute VB_Name = "ModTask_01"
+Option Explicit
+Public Const strMyTitle As String = "Eric Cheung"
+
+Function IsPerfectSq(nNum As Integer) As Boolean
+ If Sqr(nNum) - Int(Sqr(nNum)) = 0 Then
+ IsPerfectSq = True
+ Exit Function
+ End If
+ IsPerfectSq = False
+End Function
+
+Sub SortNum(ByRef nNum_01 As Integer, ByRef nNum_02 As Integer, Optional bSortAscOrder As Boolean = True)
+ Dim nTempNum As Integer
+ If _
+ bSortAscOrder And nNum_01 > nNum_02 _
+ Or Not bSortAscOrder And nNum_01 < nNum_02 _
+ Then
+ nTempNum = nNum_01
+ nNum_01 = nNum_02
+ nNum_02 = nTempNum
+ End If
+End Sub
+
+Sub Task_01()
+ ''https://www.cuemath.com/geometry/pythagorean-triples/
+
+ Dim nInput As Integer, nTemp As Integer
+ Dim nTriple_01 As Integer, nTriple_02 As Integer, nTriple_03 As Integer
+ Dim nTriple_04 As Integer, nTriple_05 As Integer, nTriple_06 As Integer
+ Dim nTriple_07 As Integer, nTriple_08 As Integer, nTriple_09 As Integer
+ Dim strMsg As String
+ Dim bFlag_01 As Boolean, bFlag_02 As Boolean
+
+ nInput = 5
+
+ '======================= SET 1, IF APPLICABLE =======================
+ nTriple_01 = nInput
+
+ If nInput Mod 2 = 0 Then
+ nTriple_02 = nInput * nInput / 4 - 1
+ nTriple_03 = nInput * nInput / 4 + 1
+ Else
+ nTriple_02 = nInput * nInput / 2 - 0.5
+ nTriple_03 = nInput * nInput / 2 + 0.5
+ End If
+
+ If nTriple_02 = 0 Then
+ MsgBox -1, vbOKOnly, strMyTitle
+ Exit Sub
+ End If
+
+ SortNum nTriple_01, nTriple_02
+
+ strMsg = "Set 1 Triple: " & nTriple_01 & ", " & nTriple_02 & ", " & nTriple_03
+ '======================= SET 1, IF APPLICABLE =======================
+
+ '======================= SET 2, IF APPLICABLE =======================
+ bFlag_01 = False
+ nTemp = (nInput + 1) * 4
+ If IsPerfectSq(nTemp) Then
+ nTriple_04 = Sqr(nTemp)
+ nTriple_05 = nInput
+ nTriple_06 = nInput + 2
+
+ bFlag_01 = True
+ End If
+
+ If Not bFlag_01 Then
+ nTemp = (nInput + 0.5) * 2
+ If IsPerfectSq(nTemp) Then
+ nTriple_04 = Sqr(nTemp)
+ nTriple_05 = nInput
+ nTriple_06 = nInput + 1
+
+ bFlag_01 = True
+ End If
+ End If
+
+ If bFlag_01 Then
+ SortNum nTriple_04, nTriple_05
+ End If
+
+ If bFlag_01 Then
+ 'Same Set
+ If _
+ nTriple_01 = nTriple_04 _
+ And nTriple_02 = nTriple_05 _
+ Then
+ bFlag_01 = False
+ End If
+ End If
+
+ If bFlag_01 Then
+ strMsg = strMsg & vbNewLine & "Set 2 Triple: " & nTriple_04 & ", " & nTriple_05 & ", " & nTriple_06
+ End If
+ '======================= SET 2, IF APPLICABLE =======================
+
+ '======================= SET 3, IF APPLICABLE =======================
+ bFlag_02 = False
+
+ nTemp = (nInput - 1) * 4
+ If IsPerfectSq(nTemp) Then
+ nTriple_07 = Sqr(nTemp)
+ nTriple_08 = nInput - 2
+ nTriple_09 = nInput
+
+ bFlag_02 = True
+ End If
+
+ If Not bFlag_02 Then
+ nTemp = (nInput - 0.5) * 2
+ If IsPerfectSq(nTemp) Then
+ nTriple_07 = Sqr(nTemp)
+ nTriple_08 = nInput - 1
+ nTriple_09 = nInput
+
+ bFlag_02 = True
+ End If
+ End If
+
+ If bFlag_02 Then
+ SortNum nTriple_07, nTriple_08
+ End If
+
+ If bFlag_02 Then
+ strMsg = strMsg & vbNewLine
+ If bFlag_01 Then
+ strMsg = strMsg & "Set 3 Triple: "
+ Else
+ strMsg = strMsg & "Set 2 Triple: "
+ End If
+ strMsg = strMsg & nTriple_07 & ", " & nTriple_08 & ", " & nTriple_09
+ End If
+ '======================= SET 3, IF APPLICABLE =======================
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-125/eric-cheung/python/ch-2.py b/challenge-125/eric-cheung/python/ch-2.py
new file mode 100644
index 0000000000..a27a4673a6
--- /dev/null
+++ b/challenge-125/eric-cheung/python/ch-2.py
@@ -0,0 +1,66 @@
+## Python Program
+## Find Max. Path In Binary Tree
+## Credit And Reference: https://www.geeksforgeeks.org/find-maximum-path-sum-in-a-binary-tree/
+
+## A Binary Tree Node
+class Node:
+ ## Constructor to create a new node
+ def __init__(self, data):
+ self.data = data
+ self.left = None
+ self.right = None
+
+## This function returns overall max. path in 'res'
+## And returns max path count going through root
+def findMaxUtil(root):
+ ## Base Case
+ if root is None:
+ return 0
+
+ ## l and r store max. path count going through left
+ ## and right child of root respectively
+ l = findMaxUtil(root.left)
+ r = findMaxUtil(root.right)
+
+ ## Max path for parent call of root. This path
+ ## must include at most one child of root
+ max_single = max(max(l, r) + 1, 1)
+
+ ## Max top represents the count when the node under
+ ## consideration is the root of the maxCount path and
+ ## no ancestor of root are there in max count path
+ max_top = max(max_single, l + r + 1)
+
+ ## Static variable to store the changes
+ ## Store the max. result
+ findMaxUtil.res = max(findMaxUtil.res, max_top)
+
+ return max_single
+
+## Return max. path count in tree with given root
+def findMaxCount(root):
+ ## Initialize result
+ findMaxUtil.res = float("-inf")
+
+ ## Compute and return result
+ findMaxUtil(root)
+ return findMaxUtil.res - 1
+
+## Driver program
+root = Node(1)
+
+root.left = Node(2)
+root.right = Node(5);
+
+root.left.left = Node(3);
+root.left.right = Node(4);
+
+root.right.left = Node(6);
+root.right.right = Node(7);
+
+root.right.right.left = Node(8);
+root.right.right.right = Node(10);
+
+root.right.right.left.left = Node(9);
+
+print "Binary Tree Diameter is ", findMaxCount(root);