Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:13
Show Gist options
  • Save rightfold/7ac091aabec55c1f40df to your computer and use it in GitHub Desktop.
Save rightfold/7ac091aabec55c1f40df to your computer and use it in GitHub Desktop.
class Day(Enum):
MONDAY = 0
TUESDAY = 1
WEDNESDAY = 2
THURSDAY = 3
FRIDAY = 4
SATURDAY = 5
SUNDAY = 6
def encode(days: set) -> int:
result = 0
for day in days:
result |= 1 << day.value
return result
def decode(bits: int) -> set:
return {Day(i) for i in range(7) if bits & 1 << i}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment