This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Phillip.M.Feldman, Phillip.M.Feldman@gmail.com, cvrebert, mark.dickinson, rhettinger, terry.reedy
Date 2011-09-19.13:41:03
SpamBayes Score 0.0043096
Marked as misclassified No
Message-id <1316439664.34.0.544715724.issue12961@psf.upfronthosting.co.za>
In-reply-to
Content
And using combinations_with_replacement, it's even a one-liner:

>>> balls_in_boxes = lambda n, k: (tuple(map(c.count, range(k))) for c in combinations_with_replacement(range(k), n))
>>> for item in balls_in_boxes(5,3): print(item)
... 
(5, 0, 0)
(4, 1, 0)
(4, 0, 1)
(3, 2, 0)
(3, 1, 1)
(3, 0, 2)
(2, 3, 0)
(2, 2, 1)
(2, 1, 2)
(2, 0, 3)
(1, 4, 0)
(1, 3, 1)
(1, 2, 2)
(1, 1, 3)
(1, 0, 4)
(0, 5, 0)
(0, 4, 1)
(0, 3, 2)
(0, 2, 3)
(0, 1, 4)
(0, 0, 5)
History
Date User Action Args
2011-09-19 13:41:04mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, terry.reedy, cvrebert, Phillip.M.Feldman@gmail.com, Phillip.M.Feldman
2011-09-19 13:41:04mark.dickinsonsetmessageid: <1316439664.34.0.544715724.issue12961@psf.upfronthosting.co.za>
2011-09-19 13:41:03mark.dickinsonlinkissue12961 messages
2011-09-19 13:41:03mark.dickinsoncreate