[Kc] Puzzle: 100 Monkeys

Garrett Goebel garrett at scriptpro.com
Wed Jan 15 09:00:11 CST 2003


                         100 Monkeys
                          2003-01-14

Note: This puzzle came to me unattributed by way of a 
      co-worker. If anyone chances by the source, please
      let me know so I can give credit.

There are 100 doors, all closed.  In a nearby cage are 100
monkeys.  The first monkey is let out, and runs along the
doors opening every one.  The second monkey is then let out,
and runs along the doors closing the 2nd, 4th, 6th,...  all
the even-numbered doors.  The third monkey is let out.  He
attends only to the 3rd, 6th, 9th,... doors (every third
door, in other words), closing any that is open and opening
any that is closed.  The fourth monkey does the same for the
4th, 8th, 12th, 16th,... doors, opening the closed ones and
closing the open ones.  The fifth monkey does the same to
the 5th, 10th, 15th,... doors, and so on.  After all 100
monkeys have done their work in this way, which doors are
left open?

Format:   m/^\d+(?:\s\d+)*$/ # scalar must match this regex

Goal:     fastest script to calculate the answer

Prize:    Your choice of O'Reilly's
          o  Perl in a Nutshell, 2nd Edition
          o  Creating Applications with Mozilla

Deadline: Answers must be submitted at least 24 hours
          before the next kc.pm meeting (February 11th)

--
Garrett Goebel
IS Development Specialist

ScriptPro                   Direct: 913.403.5261
5828 Reeds Road               Main: 913.384.1008
Mission, KS 66202              Fax: 913.384.2180
www.scriptpro.com          garrett at scriptpro.com

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/kc/attachments/20030115/40d8c495/attachment.htm


More information about the kc mailing list