wu :: forums
« wu :: forums - Circular Jail Cell »

Welcome, Guest. Please Login or Register.
Apr 20th, 2024, 5:11am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   hard
(Moderators: Icarus, ThudnBlunder, SMQ, Eigenray, towr, Grimbal, william wu)
   Circular Jail Cell
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Circular Jail Cell  (Read 3359 times)
NickH
Senior Riddler
****





   
WWW

Gender: male
Posts: 341
Circular Jail Cell  
« on: Jul 28th, 2002, 6:50am »
Quote Quote Modify Modify

Ten prisoners found their door open after 100 rounds of the drunken jailor.  They were the ones whose cell number is a perfect square.
 
Each door is opened or closed once for each factor of its cell number, including 1 and the cell number itself.  For example, for cell 12: 1, 2, 3, 4, 6, 12.
 
Most whole numbers have an even number of factors.  This is because each factor f can be paired with n/f.  The exceptions are the perfect squares, where f = n/f for precisely one factor.
IP Logged

Nick's Mathematical Puzzles
horseisahorse
Guest

Email

Re: Circular Jail Cell  
« Reply #1 on: Aug 7th, 2002, 6:00pm »
Quote Quote Modify Modify Remove Remove

Actually, I think the real-world answer would be zero, since each prisoner would have booked out of the prison as soon as the jailor opened his door during the first round.
 
IP Logged
Ivan
Guest

Email

Re: Circular Jail Cell  
« Reply #2 on: Dec 18th, 2002, 10:20pm »
Quote Quote Modify Modify Remove Remove

I got the same answer as NickH. Since I like doing things the hard way, I wrote a python program (the formatting here ain't great, look at it at http://linuxhelp.hn.org/jail-cell.py if you're interested. (with proper block spacing)):

Code:

#!/usr/bin/python
 
doors = {}
 
# create doors 1 - 100
for x in xrange(101):
    doors[x] = 0
del doors[0]
 
# first, the jailer goes to each cell
# this number will be increased in each round
sep = 1
 
# repeat until jailer falls down
while 1:
    doorcount = 1
    for x in doors:
   # check if the door by the current door skipping factor
   if doorcount % sep:
  if doors[x] == 0:
      # if it's closed, open it
      doors[x] = 1
  else:
      # if it's open, close it
      doors[x] = 0
   doorcount += 1
    sep += 1
    if sep > 100:
   # jailer falls down
   break
 
# count how many doors are open in the end
 
doors_open = 0
 
for x in doors:
    if doors[x] == 1:
   doors_open += 1
 
print doors_open
 

IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board