Message144273
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) |
|
Date |
User |
Action |
Args |
2011-09-19 13:41:04 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, terry.reedy, cvrebert, Phillip.M.Feldman@gmail.com, Phillip.M.Feldman |
2011-09-19 13:41:04 | mark.dickinson | set | messageid: <1316439664.34.0.544715724.issue12961@psf.upfronthosting.co.za> |
2011-09-19 13:41:03 | mark.dickinson | link | issue12961 messages |
2011-09-19 13:41:03 | mark.dickinson | create | |
|