aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-09-07 20:11:25 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-09-07 20:11:25 +0100
commit09af9acda817027ed71a107dfeed7d7e45fd343c (patch)
tree85dbcd27556fd9a8129f8f5102d007c01b533827
parent7e18b8378d8e1dacaba741df7f50c7660770ca1c (diff)
downloadperlweeklychallenge-club-09af9acda817027ed71a107dfeed7d7e45fd343c.tar.gz
perlweeklychallenge-club-09af9acda817027ed71a107dfeed7d7e45fd343c.tar.bz2
perlweeklychallenge-club-09af9acda817027ed71a107dfeed7d7e45fd343c.zip
- Added guest contributions by Eric Cheung.
-rwxr-xr-xchallenge-129/eric-cheung/excel-vba/Challenge_129.xlsmbin0 -> 32740 bytes
-rwxr-xr-xchallenge-129/eric-cheung/excel-vba/ch-2.bas112
-rwxr-xr-xchallenge-129/eric-cheung/python/ch-1.py72
3 files changed, 184 insertions, 0 deletions
diff --git a/challenge-129/eric-cheung/excel-vba/Challenge_129.xlsm b/challenge-129/eric-cheung/excel-vba/Challenge_129.xlsm
new file mode 100755
index 0000000000..7f43748156
--- /dev/null
+++ b/challenge-129/eric-cheung/excel-vba/Challenge_129.xlsm
Binary files differ
diff --git a/challenge-129/eric-cheung/excel-vba/ch-2.bas b/challenge-129/eric-cheung/excel-vba/ch-2.bas
new file mode 100755
index 0000000000..72bccbe36e
--- /dev/null
+++ b/challenge-129/eric-cheung/excel-vba/ch-2.bas
@@ -0,0 +1,112 @@
+Attribute VB_Name = "ModTask_02"
+Option Explicit
+Option Base 1
+
+Sub Task_02()
+
+ Dim strMsg As String
+ Dim nCnt As Integer
+
+ Dim nArrLink_01() As Variant, nArrLink_02() As Variant
+ Dim nArrAddLink() As Integer
+ Dim nLoop_01 As Integer, nLoop_02 As Integer, nLoop As Integer
+ Dim nQuotient As Integer, nRemainder As Integer, nTemp As Integer, nMax As Integer
+ Dim bFlag As Boolean
+
+ ReDim nArrAddLink(1 To 1)
+
+ ''nArrLink_01 = Array(1, 2, 3)
+ ''nArrLink_02 = Array(3, 2, 1)
+
+ nArrLink_01 = Array(1, 2, 3, 4, 5)
+ nArrLink_02 = Array(6, 5, 5)
+
+ nLoop_01 = UBound(nArrLink_01) - LBound(nArrLink_01) + 1
+ nLoop_02 = UBound(nArrLink_02) - LBound(nArrLink_02) + 1
+
+ bFlag = False
+
+ nQuotient = 0
+ nRemainder = 0
+ nCnt = 0
+
+ Do While (nLoop_01 >= 1 And nLoop_02 >= 1)
+
+ nTemp = nArrLink_01(nLoop_01) + nArrLink_02(nLoop_02) + nQuotient
+ nQuotient = Int(nTemp / 10)
+ nRemainder = nTemp Mod 10
+
+ nCnt = nCnt + 1
+
+ If bFlag Then
+ ReDim Preserve nArrAddLink(1 To nCnt)
+ Else
+ bFlag = True
+ End If
+
+ nArrAddLink(nCnt) = nRemainder
+
+ nLoop_01 = nLoop_01 - 1
+ nLoop_02 = nLoop_02 - 1
+ Loop
+
+ Do While (nLoop_01 >= 1)
+
+ nTemp = nArrLink_01(nLoop_01) + nQuotient
+ nQuotient = Int(nTemp / 10)
+ nRemainder = nTemp Mod 10
+
+ nCnt = nCnt + 1
+
+ If bFlag Then
+ ReDim Preserve nArrAddLink(1 To nCnt)
+ Else
+ bFlag = True
+ End If
+
+ nArrAddLink(nCnt) = nRemainder
+
+ nLoop_01 = nLoop_01 - 1
+ Loop
+
+ Do While (nLoop_02 >= 1)
+
+ nTemp = nArrLink_02(nLoop_02) + nQuotient
+ nQuotient = Int(nTemp / 10)
+ nRemainder = nTemp Mod 10
+
+ nCnt = nCnt + 1
+
+ If bFlag Then
+ ReDim Preserve nArrAddLink(1 To nCnt)
+ Else
+ bFlag = True
+ End If
+
+ nArrAddLink(nCnt) = nRemainder
+
+ nLoop_02 = nLoop_02 - 1
+ Loop
+
+ If nCnt Mod 2 = 0 Then
+ nMax = nCnt / 2
+ Else
+ nMax = (nCnt - 1) / 2
+ End If
+
+ For nLoop = 1 To nMax
+ nTemp = nArrAddLink(nLoop)
+ nArrAddLink(nLoop) = nArrAddLink(nCnt - nLoop + 1)
+ nArrAddLink(nCnt - nLoop + 1) = nTemp
+ Next nLoop
+
+ For nLoop = 1 To nCnt
+ If strMsg <> "" Then
+ strMsg = strMsg & ", "
+ End If
+ strMsg = strMsg & nArrAddLink(nLoop)
+ Next nLoop
+
+ MsgBox strMsg, vbOKOnly, strMyTitle
+
+End Sub
diff --git a/challenge-129/eric-cheung/python/ch-1.py b/challenge-129/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..fa1848861a
--- /dev/null
+++ b/challenge-129/eric-cheung/python/ch-1.py
@@ -0,0 +1,72 @@
+## Python3 Program
+## Find Distance from Root to Given node in a Binary Tree
+## Credit And Reference: https://www.geeksforgeeks.org/find-distance-root-given-node-binary-tree/
+
+## A class to create a new Binary Tree Node
+class newNode:
+ def __init__(self, item):
+ self.data = item
+ self.left = self.right = None
+
+## Returns -1 if x doesn't exist in tree.
+## Else returns distance of x from root
+def findDistance(root, x):
+
+ ## Base Case
+ if (root == None):
+ return -1
+
+ ## Initialize Distance
+ dist = -1
+
+ ## Check if x is present at root or in left subtree or right subtree.
+ if (root.data == x):
+ return dist + 1
+ else:
+ dist = findDistance(root.left, x)
+ if dist >= 0:
+ return dist + 1
+ else:
+ dist = findDistance(root.right, x)
+ if dist >= 0:
+ return dist + 1
+
+ return dist
+
+## Driver Code
+if __name__ == '__main__':
+
+ #### Example 1 ####
+ root_01 = newNode(1)
+
+ root_01.left = newNode(2)
+ root_01.right = newNode(3)
+
+ root_01.right.right = newNode(4)
+
+ root_01.right.right.left = newNode(5)
+ root_01.right.right.left = newNode(6)
+
+ ### Find Distance Given Node From Root
+ ## print(findDistance(root_01, 6))
+ ## print(findDistance(root_01, 4))
+ #### Example 1 ####
+
+ #### Example 2 ####
+ root_02 = newNode(1)
+
+ root_02.left = newNode(2)
+ root_02.right = newNode(3)
+
+ root_02.left.left = newNode(4)
+ root_02.right.right = newNode(5)
+
+ root_02.left.left.right = newNode(6)
+ root_02.right.right.left = newNode(7)
+
+ root_02.left.left.right.left = newNode(8)
+ root_02.left.left.right.right = newNode(9)
+
+ ## print(findDistance(root_02, 8))
+ print(findDistance(root_02, 6))
+ #### Example 2 #### \ No newline at end of file