aboutsummaryrefslogtreecommitdiff
path: root/challenge-308/eric-cheung/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-308/eric-cheung/python')
-rwxr-xr-xchallenge-308/eric-cheung/python/ch-1.py16
-rwxr-xr-xchallenge-308/eric-cheung/python/ch-2.py19
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-308/eric-cheung/python/ch-1.py b/challenge-308/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..e05d16d0b8
--- /dev/null
+++ b/challenge-308/eric-cheung/python/ch-1.py
@@ -0,0 +1,16 @@
+
+## Example 1
+## arrStr_01 = ["perl", "weekly", "challenge"]
+## arrStr_02 = ["raku", "weekly", "challenge"]
+
+## Example 2
+## arrStr_01 = ["perl", "raku", "python"]
+## arrStr_02 = ["python", "java"]
+
+## Example 3
+arrStr_01 = ["guest", "contribution"]
+arrStr_02 = ["fun", "weekly", "challenge"]
+
+arrCommon = [strLoop for strLoop in arrStr_01 if strLoop in arrStr_02]
+
+print (len(arrCommon))
diff --git a/challenge-308/eric-cheung/python/ch-2.py b/challenge-308/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..3aaa8972ac
--- /dev/null
+++ b/challenge-308/eric-cheung/python/ch-2.py
@@ -0,0 +1,19 @@
+
+## Ref.
+## If c = a ^ b, then a = c ^ b or a = b ^ c
+## Similarly, b = c ^ a or b = a ^ c
+
+## Example 1
+## arrEncoded = [1, 2, 3]
+## nInitial = 1
+
+## Example 2
+arrEncoded = [6, 2, 7, 3]
+nInitial = 4
+
+arrOutput = [nInitial]
+
+for nElem in arrEncoded:
+ arrOutput.append(arrOutput[-1] ^ nElem)
+
+print (arrOutput)