[kw-pm] UNS: picking a random list element, the hard way

Abram Hindle abram.hindle at softwareprocess.es
Fri Feb 25 11:00:59 PST 2011


We golfed about this problem a while back.

See the first challenge:

http://kw.pm.org/wiki/index.cgi?GolfChallenge

abram

On 02/25/2011 10:52 AM, Robert P. J. Day wrote:
> 
>   for your entertainment value, here's an optional exercise i'm going
> to give out in next week's perl class.  it's not so much a perl
> question as it is an algorithmic analysis question that's actually
> quite simple to code once you figure it out.
> 
>   JOB: pick a random element from a list, such that each element in
> the list is equally likely to be selected.
> 
>   sounds trivial, yes?  except here's the extra condition.  you're
> given the list elements only *one at a time*.  you're not allowed to
> store them, and you have no idea how many are coming.  and yet, you
> still need to pick a random element out of that list.
> 
>   thoughts?
> 
> rday
> _______________________________________________
> kw-pm mailing list
> kw-pm at pm.org
> http://mail.pm.org/mailman/listinfo/kw-pm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://mail.pm.org/pipermail/kw-pm/attachments/20110225/273d7541/attachment.bin>


More information about the kw-pm mailing list