diff options
Diffstat (limited to 'challenge-308/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-308/eric-cheung/python/ch-2.py | 19 |
1 files changed, 19 insertions, 0 deletions
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)
|
