Skip to content

Commit fbc0247

Browse files
committed
Add doctests to bitmask
Added doctests for count_no_of_ways method. Contributes to #9943
1 parent a71618f commit fbc0247

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

dynamic_programming/bitmask.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ def count_ways_until(self, mask, task_no):
6262
return self.dp[mask][task_no]
6363

6464
def count_no_of_ways(self, task_performed):
65+
"""
66+
Calculate the total number of ways to assign tasks to people.
67+
68+
Args:
69+
task_performed: List where task_performed[i] contains task IDs
70+
that person i can perform
71+
72+
Returns:
73+
Total number of valid task assignment ways
74+
75+
>>> tp = [[1, 3, 4], [1, 2, 5], [3, 4]]
76+
>>> AssignmentUsingBitmask(tp, 5).count_no_of_ways(tp)
77+
10
78+
>>> tp2 = [[1, 2], [1, 3]]
79+
>>> AssignmentUsingBitmask(tp2, 3).count_no_of_ways(tp2)
80+
2
81+
>>> tp3 = [[1], [2]]
82+
>>> AssignmentUsingBitmask(tp3, 2).count_no_of_ways(tp3)
83+
1
84+
"""
6585
# Store the list of persons for each task
6686
for i in range(len(task_performed)):
6787
for j in task_performed[i]:

0 commit comments

Comments
 (0)