From b7b89632947bf2c7f64b981a96a7e23b36d7f9bd Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 14 May 2024 14:25:40 +0100 Subject: - 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. --- challenge-269/eric-cheung/python/ch-1.py | 29 +++++++++++++++++++++++++++++ challenge-269/eric-cheung/python/ch-2.py | 15 +++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 challenge-269/eric-cheung/python/ch-1.py create mode 100755 challenge-269/eric-cheung/python/ch-2.py (limited to 'challenge-269/eric-cheung/python') 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) -- cgit