Re: [BangPypers] golf problem

2011-12-25 Thread Noufal Ibrahim
Kenneth Gonsalves law...@gmail.com writes: hi, a golf course has 18 holes. There are three types of hole - par 3, par 4 and par 5. For a certain type of tournament it is necessary to generate a random list of 6 holes. The only condition is that this list should contain at least one of each

Re: [BangPypers] golf problem

2011-12-25 Thread Baishampayan Ghose
a golf course has 18 holes. There are three types of hole - par 3, par 4 and par 5. For a certain type of tournament it is necessary to generate a random list of 6 holes. The only condition is that this list should contain at least one of each type of hole. What would be an elegant way of

Re: [BangPypers] golf problem

2011-12-25 Thread steve
Hi, On 12/25/2011 12:52 PM, Kenneth Gonsalves wrote: hi, a golf course has 18 holes. There are three types of hole - par 3, par 4 and par 5. For a certain type of tournament it is necessary to generate a random list of 6 holes. The only condition is that this list should contain at least

Re: [BangPypers] golf problem

2011-12-25 Thread Pratap Chakravarthy
# Initialize variables holes, bk = HOLES[:], {} ; random.shuffle( holes ) # Make buckets [ bk.setdefault(y, []).append((x,y)) for x, y in holes ] # Result print [ bk[3].pop(0), bk[4].pop(0), bk[5].pop(0) ] + random.sample( bk[3] + bk[4] + bk[5], 3 ) Some times the crude method is the best

Re: [BangPypers] golf problem

2011-12-25 Thread Kenneth Gonsalves
On Mon, 2011-12-26 at 10:01 +0530, Pratap Chakravarthy wrote: # Initialize variables holes, bk = HOLES[:], {} ; random.shuffle( holes ) # Make buckets [ bk.setdefault(y, []).append((x,y)) for x, y in holes ] # Result print [ bk[3].pop(0), bk[4].pop(0), bk[5].pop(0) ] + random.sample(

Re: [BangPypers] golf problem

2011-12-25 Thread Kenneth Gonsalves
On Mon, 2011-12-26 at 10:01 +0530, Pratap Chakravarthy wrote: # Initialize variables holes, bk = HOLES[:], {} ; random.shuffle( holes ) # Make buckets [ bk.setdefault(y, []).append((x,y)) for x, y in holes ] # Result print [ bk[3].pop(0), bk[4].pop(0), bk[5].pop(0) ] + random.sample(

Re: [BangPypers] golf problem

2011-12-25 Thread Gaurav Kalra
From: steve st...@lonetwin.net I am sorry, I didn't quite understand this bit it is necessary to generate a random list of 6 holes., since the list below has 18 elements. That means out of the 18 elements from the list, we need 6 random elements but with one constraint. In any case, whether