Does this account hold every right
Access control packs rights into a bitfield. A guard checks whether an account holds all of the rights an action needs.
- Both values are bitfields: a set bit means that right is present or required.
- Return true only when every required right is also held.
- Requiring nothing is always satisfied.
- Extra rights the account holds do not matter.
holds_every_right(held: int, needed: int) → bool
Where you start
def holds_every_right(held: int, needed: int) -> bool:
Worked examples
| Call | Result |
|---|---|
holds_every_right(7, 5) | True |
holds_every_right(5, 7) | False |
holds_every_right(0, 0) | True |
holds_every_right(8, 0) | True |
Hint
Mask what is held against what is needed. If the masked result still equals what was needed, nothing was missing.
Reference solution in Python
def holds_every_right(held: int, needed: int) -> bool:
return (held & needed) == needed