diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-05-14 14:25:40 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-05-14 14:25:40 +0100 |
| commit | b7b89632947bf2c7f64b981a96a7e23b36d7f9bd (patch) | |
| tree | a7870717f945f97f056e0b7225e15121ab8346b1 /challenge-269/eric-cheung/python | |
| parent | 3cf0a1b043c8f6c098e57675cacc11d3210df8c2 (diff) | |
| download | perlweeklychallenge-club-b7b89632947bf2c7f64b981a96a7e23b36d7f9bd.tar.gz perlweeklychallenge-club-b7b89632947bf2c7f64b981a96a7e23b36d7f9bd.tar.bz2 perlweeklychallenge-club-b7b89632947bf2c7f64b981a96a7e23b36d7f9bd.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke.
- Added solutions by Laurent Rosenfeld.
- Added solutions by E. Choroba.
- Added solutions by Mark Anderson.
- Added solutions by Feng Chang.
- Added solutions by PokGoPun.
- Added solutions by Peter Campbell Smith.
- Added solutions by Peter Meszaros.
- Added solutions by W. Luis Mochan.
- Added solutions by David Ferrone.
- Added solutions by Niels van Dijke.
- Added solutions by Arne Sommer.
- Added solutions by Dave Jacoby.
- Added solutions by Robbie Hatley.
- Added solutions by Lubos Kolouch.
- Added solutions by Asher Harvey-Smith.
Diffstat (limited to 'challenge-269/eric-cheung/python')
| -rwxr-xr-x | challenge-269/eric-cheung/python/ch-1.py | 29 | ||||
| -rwxr-xr-x | challenge-269/eric-cheung/python/ch-2.py | 15 |
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-269/eric-cheung/python/ch-1.py b/challenge-269/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..eaf14a1911 --- /dev/null +++ b/challenge-269/eric-cheung/python/ch-1.py @@ -0,0 +1,29 @@ +
+from itertools import combinations
+
+def GetBitWiseOR (arrInput):
+
+ nResult = 0
+ for rLoop in arrInput:
+ nResult = nResult | rLoop
+ return nResult
+
+## arrInt = [1, 2, 3, 4, 5] ## Example 1
+## arrInt = [2, 3, 8, 16] ## Example 2
+arrInt = [1, 2, 5, 7, 9] ## Example 3
+
+bIsEven = False
+
+for nLoop in range(2, len(arrInt) + 1):
+
+ arrCombList = combinations(arrInt, nLoop)
+
+ for arrLoop in list(arrCombList):
+ if GetBitWiseOR (arrLoop) % 2 == 0:
+ bIsEven = True
+ break
+
+ if bIsEven:
+ break
+
+print (bIsEven)
diff --git a/challenge-269/eric-cheung/python/ch-2.py b/challenge-269/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..bb95583826 --- /dev/null +++ b/challenge-269/eric-cheung/python/ch-2.py @@ -0,0 +1,15 @@ +
+## arrInt = [2, 1, 3, 4, 5] ## Example 1
+## arrInt = [3, 2, 4] ## Example 2
+arrInt = [5, 4, 3 ,8] ## Example 3
+
+arrOut_01 = [arrInt[0]]
+arrOut_02 = [arrInt[1]]
+
+for nLoop in arrInt[2:]:
+ if arrOut_01[-1] > arrOut_02[-1]:
+ arrOut_01.append(nLoop)
+ else:
+ arrOut_02.append(nLoop)
+
+print (arrOut_01 + arrOut_02)
|
