On Feb 28, 10:07 am, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> On Feb 28, 5:02 am, Michael Robertson <[EMAIL PROTECTED]> wrote:
>
> > Thanks again for your efforts here. This particular problem didn't
> > appear in any course I took...certainly similar problems did.
>
> And here's the obligatory
On Feb 28, 4:44 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> ... here is another attempt on the same principle:
>
> ---
> def boxings(n, k):
> """boxings(n, k) -> iterator
>
> Generate all ways to place n indistiguishable items into k
> distinguishable boxes
> """
On Feb 28, 2:40 am, Michael Robertson <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need a generator which produces all ways to place n indistinguishable
> items into k distinguishable boxes.
>
> For n=4, k=3, there are (4+3-1)!/(3-1)!/4! = 15 ways.
>
> (0,0,4)
[..
On Feb 28, 5:02 am, Michael Robertson <[EMAIL PROTECTED]> wrote:
> Thanks again for your efforts here. This particular problem didn't
> appear in any course I took...certainly similar problems did.
And here's the obligatory not-very-obfuscated one-liner:
from itertools import combinations as c;
[EMAIL PROTECTED] wrote the following on 02/28/2008 12:36 AM:
> On Feb 27, 8:47 pm, Michael Robertson <[EMAIL PROTECTED]> wrote:
> Your only casualty here is all the zeroes in (4,0,0,..). You don't
> want to swap k_2 and k_3 in (4,0,0). (Is that what permutation
> means?)
Correct. Though by 'pe
On Feb 27, 8:47 pm, Michael Robertson <[EMAIL PROTECTED]> wrote:
> Michael Robertson wrote the following on 02/27/2008 06:40 PM:
>
> > Hi,
>
> > I need a generator which produces all ways to place n indistinguishable
> > items into k distinguishable boxes.
>
&g
On Feb 27, 10:46 pm, [EMAIL PROTECTED] wrote:
> On Feb 27, 10:41 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
>
> > On Feb 27, 11:38 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
>
> > > yield map(len, (''.join(s)).split('|'))
>
> > That line should have been just:
>
> > yi
On Feb 27, 10:49 pm, Michael Robertson <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote the following on 02/27/2008 08:46 PM:
>
> > Just sort the list in text-ascending order, and it's pretty clear.
>
> Indeed. After trying Mark's solution, I saw that it sorted in a very
> nice manner.
You co
[EMAIL PROTECTED] wrote the following on 02/27/2008 08:46 PM:
> Just sort the list in text-ascending order, and it's pretty clear.
Indeed. After trying Mark's solution, I saw that it sorted in a very
nice manner.
--
http://mail.python.org/mailman/listinfo/python-list
On Feb 27, 10:41 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> On Feb 27, 11:38 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
>
> > yield map(len, (''.join(s)).split('|'))
>
> That line should have been just:
>
> yield map(len, s.split('|'))
>
> of course.
>
> Mark
It's e
On Feb 27, 11:38 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> yield map(len, (''.join(s)).split('|'))
That line should have been just:
yield map(len, s.split('|'))
of course.
Mark
--
http://mail.python.org/mailman/listinfo/python-list
Here's a possible solution. I'm sure others will comment on how to
fix up its inefficiencies (like the potentially slow string
concatenations...).
def comb(n, k):
if n == k == 0:
yield ''
else:
if n > 0:
for x in comb(n-1, k):
yield ' ' + x
[EMAIL PROTECTED] wrote the following on 02/27/2008 08:14 PM:
> On Feb 27, 10:12 pm, [EMAIL PROTECTED] wrote:
>>> For n=4, k=3, there are (4+3-1)!/(3-1)!/4! = 15 ways.
>>> (0,0,4)
>>> (0,4,0)
>>> (4,0,0)
>>> (0,2,2)
>>> (2,0,2)
>>> (2,2,0)
>>> (0,1,3)
>>> (0,3,1)
>>> (3,0,1)
>>> (3,1,0)
>>> (1,1,2
On Feb 27, 10:12 pm, [EMAIL PROTECTED] wrote:
> On Feb 27, 8:40 pm, Michael Robertson <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi,
>
> > I need a generator which produces all ways to place n indistinguishable
> > items into k distinguishable boxes.
&g
On Feb 27, 8:40 pm, Michael Robertson <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need a generator which produces all ways to place n indistinguishable
> items into k distinguishable boxes.
>
> For n=4, k=3, there are (4+3-1)!/(3-1)!/4! = 15 ways.
>
> (0,0,4)
> (0,4,
On Feb 27, 9:31 pm, Michael Robertson <[EMAIL PROTECTED]> wrote:
> Michael Robertson wrote the following on 02/27/2008 06:40 PM:
>
> > I need a generator which produces all ways to place n indistinguishable
> > items into k distinguishable boxes.
>
> I found:
>
>
On Feb 27, 9:03 pm, Michael Robertson <[EMAIL PROTECTED]> wrote:
> Roy Smith wrote the following on 02/27/2008 06:56 PM:
>
> > What course is this homework problem for?
>
> None. I assume you have an answer to this *trivial* problem...
>
> It's actually a very general question relating to a very s
Michael Robertson wrote the following on 02/27/2008 06:40 PM:
> I need a generator which produces all ways to place n indistinguishable
> items into k distinguishable boxes.
I found:
http://portal.acm.org/citation.cfm?doid=363347.363390
Do anyone know if there are better algorithms tha
Roy Smith wrote the following on 02/27/2008 06:56 PM:
> What course is this homework problem for?
None. I assume you have an answer to this *trivial* problem...
It's actually a very general question relating to a very specific
problem I am working on. Normally, I do not reply to such snide
re
In article <[EMAIL PROTECTED]>,
Michael Robertson <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need a generator which produces all ways to place n indistinguishable
> items into k distinguishable boxes.
>
> For n=4, k=3, there are (4+3-1)!/(3-1)!/4! = 15 ways.
&
Michael Robertson wrote the following on 02/27/2008 06:40 PM:
> Hi,
>
> I need a generator which produces all ways to place n indistinguishable
> items into k distinguishable boxes.
>
My first thought was to generate all integer partitions of n, and then
generate all pe
Hi,
I need a generator which produces all ways to place n indistinguishable
items into k distinguishable boxes.
For n=4, k=3, there are (4+3-1)!/(3-1)!/4! = 15 ways.
(0,0,4)
(0,4,0)
(4,0,0)
(0,2,2)
(2,0,2)
(2,2,0)
(0,1,3)
(0,3,1)
(3,0,1)
(3,1,0)
(1,1,2)
(1,2,1)
(2,1,1)
The generator needs
22 matches
Mail list logo