You could go through and add every number you come across and subtract that from the total you would get if they were all there, and the number that is left would be the one missing.

Justin

Jonathan Duncan wrote:


Begin forwarded message:

From: "Sasha Pachev" <[EMAIL PROTECTED]>

A question was asked a friend of mine during his interview with
Microsoft. It is hard to believe that I would have a friend that would
even consider interviewing with Microsoft, or at least I would be
ashamed to admit it on this list, but well, I do :-)

I decided to port this problem to the New Testament theme, and also
make it more friendly for non-programmers. Anybody who knows how to
use a calculator should be comfortable with it. So here it is:

You have 100 sheep in a flock and they are all numbered. Each has an
identification tag with a number -  1 through 100. One of them is
lost. Other sheep are scattered over the pasture and cannot be
examined in sequential order of their numbers. Come up with a method
that would allow you to quickly identify the lost sheep. The use of a
simple arithmetical calculator is allowed. The use of a pen or any
other note-taking instrument is not (to disallow the trivial but
unscaleable roll-call method).


Those on the PLUG list already saw this, but I thought it might be a fun way to exercise your PHP and math skills on. I came up with a PHP solution. Now I would like to see how others would solve the same problem.

Jonathan

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net




_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to