< No Frames > tag is used for


No Answer is Posted For this Question
Be the First to Post Answer

Post New Answer

More Programming Languages AllOther Interview Questions

This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells them, "You may meet today and plan a strategy. But after today, you will be in isolated cells and will have no communication with one another. "In the prison is a switch room, which contains two light switches labeled A and B, each of which can be in either the 'on' or the 'off' position. I am not telling you their present positions. The switches are not connected to anything. "After today, from time to time whenever I feel so inclined, I will select one prisoner at random and escort him to the switch room. This prisoner will select one of the two switches and reverse its position. He must move one, but only one of the switches. He can't move both but he can't move none either. Then he'll be led back to his cell. "No one else will enter the switch room until I lead the next prisoner there, and he'll be instructed to do the same thing. I'm going to choose prisoners at random. I may choose the same guy three times in a row, or I may jump around and come back. "But, given enough time, everyone will eventually visit the switch room as many times as everyone else. At any time anyone of you may declare to me, 'We have all visited the switch room.' and be 100% sure. "If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will be fed to the alligators." What is the strategy they come up with so that they can be free?

6 Answers  


I'm trying to solve this. But I'm not figuring the right solution. Can some one help what the answer is for the question below? You can use as many variables as you need, there are no negative numbers, all numbers are integers. You do not know the size of the integers, they could be infinitely large, so you can't count on truncating at any point. There are NO comparisons allowed, no if statements or anything like that. There are only four operations you can do on a variable. 1) You can set a variable to 0. 2) You can set a variable = another variable. 3) You can increment a variable (only by 1), and it's a post increment. 4) You can loop. So, if you were to say loop(v1) and v1 = 10, your loop would execute 10 times, but the value in v1 wouldn't change so the first line in the loop can change value of v1 without changing the number of times you loop. You need to do 3 things. 1) Write a function that decrements by 1. 2) Write a function that subtracts one variable from another. 3) Write a function that divides one variable by another. 4) See if you can implement all 3 using at most 4 variables. Meaning, you're not making function calls now, you're making macros. And at most you can have 4 variables. The restriction really only applies to divide, the other 2 are easy to do with 4 vars or less. Division on the other hand is dependent on the other 2 functions, so, if subtract requires 3 variables, then divide only has 1 variable left unchanged after a call to subtract. Basically, just make your function calls to decrement and subtract so you pass your vars in by reference, and you can't declare any new variables in a function, what you pass in is all it gets.

1 Answers   Microsoft,


given a height balanced tree. If we add one more node , how many nodes gets unbalanced ?

2 Answers   Hughes,


in IBM PC -AT.WAT AT REFERS TO?

0 Answers   IBM,


How to convert numeric value into words in c#????plz suggest me the coding of this question???

1 Answers   NIIT,






What are the limitation in using querystring in .net?

1 Answers   Tesco,


what is oops?

4 Answers   Satyam,


A string of charaters were given. Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE

7 Answers   Nagarro,


What is ur porject Architecture? If anyone ask what i have to specify here..

0 Answers  


Please forward important interview and basic questions in VB6 on my email id: usneha_16@yahoo.co.in

0 Answers  


could you please tell me how to draw the calibration curve for HPLC {the software which we are using}?

0 Answers  


What is nocopy in plsql?

1 Answers   IBA Health,


Categories