[Kc] Puzzle: 100 Monkeys (Last chance to enter a solution)

Garrett Goebel garrett at scriptpro.com
Mon Feb 10 15:10:30 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: 
o  fastest script to calculate the answer 
o  shortest script to calculate the answer 


Prize:    Your choice of O'Reilly book 
o  Computer Science & Perl 
o  Creating Web Applications with Mozilla 
o  Designing Embedded Hardware 
o  Perl CD Bookshelf, Version 3.0 
o  Perl Graphics Programming 
o  Perl in a Nutshell, 2nd Edition 
o  Programming Web Services with Perl 

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

* As long as you get your final entries in by tomorrow morning it'll be
okay.

-- 
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 dot com 
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/kc/attachments/20030210/7eabbfe7/attachment.htm


More information about the kc mailing list