That's not as easy as it seems. See:
https://en.wikipedia.org/wiki/Scunthorpe_problem
and
http://stackoverflow.com/questions/273516/how-do-you-impleme...
https://en.wikipedia.org/wiki/Scunthorpe_problem
and
http://stackoverflow.com/questions/273516/how-do-you-impleme...