Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- binaryLen = lambda n: math.floor(math.log2(n)) + 1
- def findNextMx(mx, ar , exclude_list):
- '''Find the next max of same bin len as mx.'''
- logmx = binaryLen(mx)
- nextmx = float('-inf')
- for n in ar:
- if n not in exclude_list and n > nextmx:
- nextmx = n
- if binaryLen(nextmx) != logmx:
- mx = nextmx
- return findNextMx(nextmx, ar, exclude_list + [nextmx])
- return mx, nextmx
- def maxAnd(ar):
- mx = max(ar)
- mx, nextmx = findNextMx(mx, ar , [mx])
- return mx & nextmx
- def maxOR(ar):
- mx = max(ar)
- mx, nextmx = findNextMx(mx, ar , [mx])
- return mx | nextmx
- def sumMaxAndOr(ar):
- mx = max(ar)
- mx, nextmx = findNextMx(mx, ar , [mx])
- return (mx & nextmx) + (mx | nextmx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement