please only answer those who are very clear on this topic :)
Let's say I have 5 baskets that store a maximum of 20 eggs each , how do I distribute 80 eggs in those 5 baskets without exceeding the limit of 20 eggs per basket, but yes or if I have to distribute the eggs in the 5 baskets.
I know that the random module chooses a random number between two numbers that I define, eg:random.randint(15, 20)
I would grab a random number between 15 and 20, but in this way the numbers chosen by the random function may not give me the 80 eggs that I want to give out and they give me less.
My idea is that in the end I will have a dictionary like this where all the eggs are distributed in the baskets randomly (if someone has another proposal that is not more complicated to store them, welcome!):
canastas = {"canasta1" : 15 , "canasta2": 18, "canasta3": 20, etc }
I am one of those who are not completely clear on the subject, but still, I can at least propose a "brute force" solution that is totally feasible. The idea is:
This more or less would be the idea:
As you can see, by simulating 1,000 possible basket combinations, we have found several possibilities that meet our assumptions. One possibility to improve this algorithm is to finish when we find the first successful combination, which is what is required, for example:
And by the way, if you look up a dictionary you can transform any of the combination lists you have:
For the next ones who see this question and want a slightly more summarized and easy to understand answer. I did it like this because they asked me for everything in one function:
OUTPUT: