Question: Python assignment. 1. Use product() to make a function which counts the number of ways you can place unlabeled balls in labeled urns given lower

Python assignment.

1. Use product() to make a function which counts the number of ways you can place unlabeled balls in labeled urns given lower and upper bounds on how many balls each urn can have. Your function should take in four integers

n - number of balls

k - number of urns

lower - the smallest number of balls allowed in an urn

upper - the largest number of balls allowed in an urn

It should spit out a list of all the possible configurations.

bounded_urns(n,k,lower,upper)

>>> bounded_urns(13,4,2,4) [(2, 3, 4, 4), (2, 4, 3, 4), (2, 4, 4, 3), (3, 2, 4, 4), (3, 3, 3, 4), (3, 3, 4, 3), (3, 4, 2, 4), (3, 4, 3, 3), (3, 4, 4, 2), (4, 2, 3, 4), (4, 2, 4, 3), (4, 3, 2, 4), (4, 3, 3, 3), (4, 3, 4, 2), (4, 4, 2, 3), (4, 4, 3, 2)]

>>> bounded_urns(5,7,0,1) [(0, 0, 1, 1, 1, 1, 1), (0, 1, 0, 1, 1, 1, 1), (0, 1, 1, 0, 1, 1, 1), (0, 1, 1, 1, 0, 1, 1), (0, 1, 1, 1, 1, 0, 1), (0, 1, 1, 1, 1, 1, 0), (1, 0, 0, 1, 1, 1, 1), (1, 0, 1, 0, 1, 1, 1), (1, 0, 1, 1, 0, 1, 1), (1, 0, 1, 1, 1, 0, 1), (1, 0, 1, 1, 1, 1, 0), (1, 1, 0, 0, 1, 1, 1), (1, 1, 0, 1, 0, 1, 1), (1, 1, 0, 1, 1, 0, 1), (1, 1, 0, 1, 1, 1, 0), (1, 1, 1, 0, 0, 1, 1), (1, 1, 1, 0, 1, 0, 1), (1, 1, 1, 0, 1, 1, 0), (1, 1, 1, 1, 0, 0, 1), (1, 1, 1, 1, 0, 1, 0), (1, 1, 1, 1, 1, 0, 0)]

>>> len(bounded_urns(20,6,0,4))

126

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!