Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Created May 5, 2021 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueleresca/7f9df308498a1c5cf3c3762f837602b6 to your computer and use it in GitHub Desktop.
Save samueleresca/7f9df308498a1c5cf3c3762f837602b6 to your computer and use it in GitHub Desktop.
"""
Original code available at: https://github.com/mwhittaker/quoracle/blob/d83a811a905a51fc13ebc00ddac036d559463380/quoracle/quorum_system.py#L276
"""
def _f_resilient_quorums(self,
f: int,
xs: List[T],
e: Expr) -> Iterator[Set[T]]:
"""
Consider a set X of elements in xs. We say X is f-resilient if, despite
removing an arbitrary set of f elements from X, X is a quorum in e.
_f_resilient_quorums returns the set of all f-resilient quorums.
"""
assert f >= 1
def helper(s: Set[T], i: int) -> Iterator[Set[T]]:
if all(e.is_quorum(s - set(failure))
for failure in itertools.combinations(s, min(f, len(s)))):
yield set(s)
return
for j in range(i, len(xs)):
s.add(xs[j])
yield from helper(s, j + 1)
s.remove(xs[j])
return helper(set(), 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment