[BangPypers] golf problem

Pratap Chakravarthy prataprc at gmail.com
Mon Dec 26 05:31:30 CET 2011


# 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 method ?

A crude analysis on the above logic and number of passes made on the
sample list.
1. To copy HOLES to holes
2. To shuffle holes using random.shuffle()
3. To make buckets
4. random.sample() is another crude algorithm which seems to be in
between O(n) and O(n^2) - a wild guess.


More information about the BangPypers mailing list