INNER CODE UNIT · Python
prefix_or0
lschoe/mpyc · demos/PrefixOrExplained.py:60
def prefix_or0(x):
return list(itertools.accumulate(x, operator.or_))
def prefix_or1(x):
return list(mpyc.mpctools.accumulate(x, operator.or_))
# Given a list of bits `x`, both `prefix_or0(x)` and `prefix_or1(x)` compute the or over all (nonempty) prefixes of `x`.
# In[5]:
x = [0, 0, 0, 1, 0, 0, 1, 0]
print(prefix_or0(x))
print(prefix_or1(x))
# Once we reach the first (leftmost) `1` in the input, this bit and all succeeding bits will be `1` in the output.