# [Kc] Puzzle: 100 Monkeys (More prizes update)

Garrett Goebel garrett at scriptpro.com
Mon Jan 27 12:53:55 CST 2003

```Because O'Reilly has given us so many excellent books, I'm going to add
another prize category to this month's puzzle.

First prize:  fastest
Second prize: shortest

*  There will be 2 winners (no single person can get 1st and 2nd)
** I will not be participating for a prize

And again, because I forgot to update it in the text below. The prize is the
winner's choice of one of the following:

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

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

before the next kc.pm meeting (February 11th)

--
Garrett Goebel
IS Development Specialist
ScriptPro                   Direct: 913.403.5261