The teacher in a certain class room allows you to pass a paper with an assignment around, and whomever it ends up on has to do it. The only two rules are you can't pass it to someone who already has had it and you can only pass it to the person to the left, right, forward, or backward.
In a room of 30 students arranged in a 6 by 5 grid, the teacher starts out with the assignment somewhere on the front row of 6 students. At some point someone is stuck holding the assignment because all his neighbors have had it and passed it on to someone else. If this happens after every student in the room has had it, what is the probablity, for each individual, that he or she turns out to be the lucky winner of the assignment?
(In reply to
A variation by Charlie)
BTW, the code for allowing passing in any of the 8 directions, including diagonal is:
DEFINT A-Z
DIM drCt(-2 TO 2) AS LONG
DIM dcCt(-2 TO 2) AS LONG
RANDOMIZE TIMER
OPEN "50megs.1-5" FOR BINARY AS #1
st$ = " "
DO
REDIM student(6, 7)' unused elements outside bound
f = INT(RND(1) * 6 + 1)
student(1, f) = 1
row = 1: col = f
FOR pass = 2 TO 30
DO
DO
IF supply < 3 THEN
GET #1, , st$
IF EOF(1) THEN PRINT "Ran out of random #'s": END
source = source * 256 + ASC(st$)
supply = supply + 8
END IF
choice = source MOD 8
source = source \ 8
supply = supply - 3
SELECT CASE choice
CASE 0
dr = 1: dc = -1
CASE 1
dr = 1: dc = 0
CASE 2
dr = 1: dc = 1
CASE 3
dr = 0: dc = -1
CASE 4
dr = 0: dc = 1
CASE 5
dr = -1: dc = -1
CASE 6
dr = -1: dc = 0
CASE 7
dr = -1: dc = 1
END SELECT
LOOP UNTIL (dr OR dc)
drCt(dr) = drCt(dr) + 1
dcCt(dc) = dcCt(dc) + 1
newRow = row + dr: newCol = col + dc
LOOP UNTIL newRow > 0 AND newRow < 6 AND newCol > 0 AND newCol < 7 AND student(newRow, newCol) = 0
row = newRow: col = newCol
p = pass
surr = 1
FOR dr = -1 TO 1
FOR dc = -1 TO 1
IF dr <> 0 OR dc <> 0 THEN
newRow = row + dr: newCol = col + dc
IF newRow > 0 AND newRow < 6 AND newCol > 0 AND newCol < 7 THEN
IF student(newRow, newCol) = 0 THEN
surr = 0: EXIT FOR
END IF
END IF
END IF
NEXT
IF surr = 0 THEN EXIT FOR
NEXT
IF surr THEN EXIT FOR
student(row, col) = 1
NEXT
IF p = 30 THEN
tot(row, col) = tot(row, col) + 1: overTot = overTot + 1
fCount = fCount + 1
PRINT row, col, fCount, tr&
' FOR i = -2 TO 2: PRINT drCt(i); : NEXT
' PRINT
' FOR i = -2 TO 2: PRINT dcCt(i); : NEXT
' PRINT
END IF
tr& = tr& + 1
LOOP UNTIL fCount = 10000
FOR row = 1 TO 5
FOR col = 1 TO 6
PRINT USING "#####"; tot(row, col);
NEXT
PRINT
NEXT
PRINT
FOR row = 1 TO 5
FOR col = 1 TO 3
PRINT USING "#####"; tot(row, col) + tot(row, 7 - col);
NEXT
PRINT
NEXT
PRINT
PRINT tr&
CLOSE
|
Posted by Charlie
on 2004-06-25 11:05:03 |