From e9d030e5fd8fa107797fac1489bca6ce2724d212 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Mon, 10 Feb 2025 20:39:47 +0000 Subject: - Added solutions by Eric Cheung. - Added solutions by Ulrich Rieke. - Added solutions by Mark Anderson. - Added solutions by David Ferrone. - Added solutions by Ali Moradi. - Added solutions by Niels van Dijke. - Added solutions by Peter Pentchev. - Added solutions by E. Choroba. - Added solutions by Peter Meszaros. - Added solutions by Thomas Kohler. - Added solutions by W. Luis Mochan. - Added solutions by BarrOff. --- challenge-308/eric-cheung/python/ch-1.py | 16 ++++++++++++++++ challenge-308/eric-cheung/python/ch-2.py | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 challenge-308/eric-cheung/python/ch-1.py create mode 100755 challenge-308/eric-cheung/python/ch-2.py (limited to 'challenge-308/eric-cheung/python') 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) -- cgit