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
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
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
# 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
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(
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(
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