All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Select an Item (Posted on 2004-10-22) Difficulty: 3 of 5
Your job is to pick one ball from a collection of balls in such a way that every ball has an equal probability of being selected. The twist is that you do not know how many balls are in the collection. Each ball will be handed to you, one at a time. As each ball is handed to you you must decide (by some random process) whether to keep or discard the ball.

You must always be holding one and only one ball so that when a new ball is given to you, you must either discard it or keep it by discarding the previously held ball.

See The Solution Submitted by Brian Smith    
Rating: 3.2500 (8 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(2): No Subject | Comment 10 of 13 |
(In reply to re: No Subject by bob909)

Yes, your method is random, but it doesn't guarantee that each ball will have the same probability of being chosen.
  Posted by Federico Kereki on 2004-10-23 12:09:52

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (11)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information