Sunday, May 24, 2015

IQ Level Test



Ans:

Five
Count the letters in the spelling of the number.

Tuesday, May 19, 2015

The Prisoners and Hat Problem


 four prisoners are arrested for a crime, but the jail is full and the jailer has nowhere to put them. He eventually comes up with the solution of giving them a puzzle so if they succeed they can go free but if they fail they are executed.

If any prisoner can figure out and say to the jailer what color hat he has on his head
 all four prisoners go free. If any prisoner suggests an incorrect answer, all four prisoners are executed. The puzzle is to find how the prisoners can escape, regardless of how the jailer distributes the hats.The jailer puts three of the men sitting in a line. The fourth man is put behind a screen (or in a separate room). He gives all four men party hats (as in diagram). The jailer explains that there are two red and two blue hats; that each prisoner is wearing one of the hats; and that each of the prisoners only see the hats in front of him but not on himself or behind him. The fourth man behind the screen can't see or be seen by any other prisoner. No communication between the prisoners is allowed.



Answer:
For the sake of explanation let's label the prisoners in line order A B and C. Thus B can see C (and C's hat color) and A can see B and C.
The prisoners know that there are only two hats of each color. So if A observes that B and C have hats of the same color, A would deduce that his own hat is the opposite color. However, if B and C have hats of different colors, then A can say nothing. The key is that prisoner B, after allowing an appropriate interval, and knowing what A would do, can deduce that if A says nothing the hats on B and C must be different. Being able to see C's hat he can deduce his own hat color.
In common with many puzzles of this type, the solution relies on the assumption that all participants are totally rational and are intelligent enough to make the appropriate deductions.

Thursday, May 14, 2015

Towers of Hanoi

Given a game board with four pegs and a set of disks of different diameter all stacked from smallest to largest on the leftmost peg, move all of the disks to the rightmost peg following these two rules. First, only one disk may be moved at a time. Second, a larger diameter disk may never be placed on a smaller disk.


Answer:




Wednesday, May 6, 2015

Guess the number.

Given the numbers 1 to 1000, what is the minimum number of guesses needed to find a specific number if you are given the hint ‘higher’ or ‘lower’ for each guess you make?


Ans:

Using Binary Search to find a number from 1 to 1,000

The approach most programmers would take is by starting your guess in the middle of the set of numbers, and then continuing to divide the set of numbers in half with each guess. This approach to guessing (or “searching” for the number) is known as a binary search to most software engineers, and it is also known as a half-interval search. Let’s go through an example of how the binary search would work so that you can further understand the approach to solving this problem.

An Example of using the binary search
So, let’s say the number you were trying to guess is a ‘1’. Then, you would start from the middle of 1,000 – which is 500. The person giving you hints would keep saying lower – and you would end up with something like this sequence of numbers to represent your guesses:
500, 250, 125, 63, 32, 16, 8, 4, 2, 1
Counting the number of guesses above would give you 10, which is our answer to the maximum number of guesses to find a number between 1 and 1000. In a binary search, if you take the log base 2 of the number of numbers (in this case, 1000), that would also give you the maximum number of guesses to find the correct number. So, if we take the log base 2 of 1,000 it would give us 9.965. Since you can’t possibly have a fraction of a guess, the result of log base 2 of 1000 should be rounded up to a whole number, which is 10, and the answer.