Here, s coding puzzle:
You have 1,000 doors.
You have 1,000 people
The first person is instructed to open all the doors.
The second person is instructed to close every other door.
The third person is to close every third door, if it’s open, or open it if it’s closed.
This repeats until all 1,000 people do their task.
Question: How many doors are now open?
This is the code I came with to solve the problem. I used Excel to avoid array hassles)Code:Sub Setup() For x = 1 To 1000 Cells(x, 1) = "Open" Next x End Sub Sub OpenAndClose() For y = 2 To 1000 For z = y To 1000 Step y If Cells(z, 1) = "Open" Then Cells(z, 1) = "Close" Else Cells(z, 1) = "Open" End If Next Next End Sub
The answer is 31 open doors.
Anyone come up withsomething different?




Reply With Quote