dynamic_programming.iterating_through_submasks

Author : Syed Faizan (3rd Year Student IIIT Pune) github : faizan2700 You are given a bitmask m and you want to efficiently iterate through all of its submasks. The mask s is submask of m if only bits that were included in bitmask are set

Functions

list_of_submasks(→ list[int])

Args:

Module Contents

dynamic_programming.iterating_through_submasks.list_of_submasks(mask: int) list[int]
Args:
masknumber which shows mask ( always integer > 0, zero does not have any

submasks )

Returns:

all_submasks : the list of submasks of mask (mask s is called submask of mask m if only bits that were included in original mask are set

Raises:

AssertionError: mask not positive integer

>>> list_of_submasks(15)
[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
>>> list_of_submasks(13)
[13, 12, 9, 8, 5, 4, 1]
>>> list_of_submasks(-7)  
Traceback (most recent call last):
    ...
AssertionError: mask needs to be positive integer, your input -7
>>> list_of_submasks(0)  
Traceback (most recent call last):
    ...
AssertionError: mask needs to be positive integer, your input 0