There's a circular rotating disc composed of two semi circles, one white and the other black. You are given sensors that you can place directly above the disc. These sensors send a 0 when the region below it changes from white to black and 1 when it changes from black to white. The speed of rotation of the disc is not predictable
a. What is the minimum number of sensors you need to determine the direction of rotation? Also draw a state change diagram
b. What is the optimal placement of the sensors in order to optimise the time taken to detect the direction of rotation
c. If you are given just one sensor, what additional constraints will you bring in to the equation?
2 sensors, put sensor A on the twelve’o clock, put sensor B on the three’o clock
If firstly A gets a value and then B gets a value, if(A.value==B.value) clockwise
If firstly A gets a value and then B gets a value, if(A.value!=B.value) anticlockwise
If firstly B gets a value and then A gets a value, if(A.value==B.value) anticlockwise
If firstly B gets a value and then A gets a value, if(A.value!=B.value) clockwise
Showing posts with label brainteaser. Show all posts
Showing posts with label brainteaser. Show all posts
Feb 9, 2009
Feb 7, 2009
You and your opponent are playing a game. The rule is that you start the game by saying a sequence of continuous integers. The sequence may have a len
You and your opponent are playing a game. The rule is that you start the game by saying a sequence of continuous integers. The sequence may have a length of 1, 2, or 3. The sequence should start from 1. So you could start the game by saying either {1}, or {1,2}, or {1,2,3}. Your opponent will follow your sequence by saying his sequence of length 1, 2, or 3. His sequence starts from where you stop. E.g. if you say {1,2}, then you opponent may say either {3}, or {3,4}, or {3,4,5}; and you follow your opponent's sequence in the same manner. The game continues until one person says 30 in his sequence and that person wins. The problem asks you to design a strategy so that you will win (i.e. you are the first to be able to say 30 in your sequence).
The first player should start with {1,2}.
For the second player's next six moves, the first player should respond with a sequence of length:
3 if the second player's sequence was of length 1
2 if the second player's sequence was of length 2
1 if the second player's sequence was of length 3
At the end of this sequence of moves, the first player's last move will be {26} or {25,26} or {24,25,26} because 2 + 6 x 4 = 26.
At that point, it will be the second player's turn to make a move, who will be able to play {27} or {27,28} or {27,28,29}.
The first player can then win by responding with {28,29,30} or {29,30} or {30}.
The first player should start with {1,2}.
For the second player's next six moves, the first player should respond with a sequence of length:
3 if the second player's sequence was of length 1
2 if the second player's sequence was of length 2
1 if the second player's sequence was of length 3
At the end of this sequence of moves, the first player's last move will be {26} or {25,26} or {24,25,26} because 2 + 6 x 4 = 26.
At that point, it will be the second player's turn to make a move, who will be able to play {27} or {27,28} or {27,28,29}.
The first player can then win by responding with {28,29,30} or {29,30} or {30}.
Feb 5, 2009
You have b boxes and n dollars. If I want any amount of money, from zero to n dollars, you must be able to hand me zero to b boxes so that I get exact
You have b boxes and n dollars. If I want any amount of money, from zero to n dollars, you must be able to hand me zero to b boxes so that I get exactly what I request.
divide the amount into powers-of-two sizes: 1 2 4 8 16 32 etc
divide the amount into powers-of-two sizes: 1 2 4 8 16 32 etc
Feb 1, 2009
There are 100 prisoners in a jail. Since the jail will be closed, the prisoners are either released or executed. They are lined up in a single line in
There are 100 prisoners in a jail. Since the jail will be closed, the prisoners are either released or executed. They are lined up in a single line in the backyard, and the guardians put a hat every prisoner's head, colored either black or white. The line is formed in a way that each prisoner can see the color of the hat of every prisoner in front of him, but none behind him, and no one can see their own hats. This way the first in line doesn't see any, the second sees the first, the third the first two, etc.
Now, starting with the last one in the line, every prisoner has to shout a color, black or white. If what he says matches his hat's color, he is released, otherwise he's shot in the head. All the other prisoners will hear what he shouted, and they will also hear weather he was shot or not. There's no communication between the prisoners, they have no knowledge of how many black/white hats there are in total, but they can agree on a strategy before the whole process starts.
What is the best strategy to save the most number of prisoners? How many prisoners can be saved for sure?
The last person in the line has no information. So he can only hope that he is correct with a 50% chance. So he decides to help out his fellow prisoners. He says white if the number of caps white caps he sees on the heads of the other 99 prisoners is even, and black if it is odd.
Now the 99th person, knows whether to total number of caps is even, and he can see the other 98 caps. So he can deduce the color of had on his head, and would be let off.
The 98th person knows whether the total number of caps is even. He also knows the color of the cap on the 99th person's head. So he can compute the color of the cap on his head.
This way each person is able to correctly answer except the last person in line. There is a 50% chance that the last person will also be released.
Now, starting with the last one in the line, every prisoner has to shout a color, black or white. If what he says matches his hat's color, he is released, otherwise he's shot in the head. All the other prisoners will hear what he shouted, and they will also hear weather he was shot or not. There's no communication between the prisoners, they have no knowledge of how many black/white hats there are in total, but they can agree on a strategy before the whole process starts.
What is the best strategy to save the most number of prisoners? How many prisoners can be saved for sure?
The last person in the line has no information. So he can only hope that he is correct with a 50% chance. So he decides to help out his fellow prisoners. He says white if the number of caps white caps he sees on the heads of the other 99 prisoners is even, and black if it is odd.
Now the 99th person, knows whether to total number of caps is even, and he can see the other 98 caps. So he can deduce the color of had on his head, and would be let off.
The 98th person knows whether the total number of caps is even. He also knows the color of the cap on the 99th person's head. So he can compute the color of the cap on his head.
This way each person is able to correctly answer except the last person in line. There is a 50% chance that the last person will also be released.
Jan 24, 2009
Consider a row of N pegs. Two players take alternate turns removing any individual peg or any 2 adjacent pegs. For what values of N does first playe
Consider a row of N pegs. Two players take alternate turns removing any individual peg or any 2 adjacent pegs.
For what values of N does first player win and what strategy does he use.
Assuming that the player who takes the last peg wins...
The first player has a winning strategy for any N.
On his first move, If N is even, he takes the middle two pegs and if N is odd he takes the middle peg. This divides the pegs into two groups of equal numbers of pegs.
On subsequent moves, he just mimics the move made by the second player, but in the opposite group.
Indeed, this is very closely related to the round table and dishes problem :-)
For what values of N does first player win and what strategy does he use.
Assuming that the player who takes the last peg wins...
The first player has a winning strategy for any N.
On his first move, If N is even, he takes the middle two pegs and if N is odd he takes the middle peg. This divides the pegs into two groups of equal numbers of pegs.
On subsequent moves, he just mimics the move made by the second player, but in the opposite group.
Indeed, this is very closely related to the round table and dishes problem :-)
Jan 20, 2009
There is a blank disc( like a CD). You are given two colors of paint (black and white). A sensor can recognize the color painted on the disc and produ
There is a blank disc( like a CD). You are given two colors of paint (black and white). A sensor can recognize the color painted on the disc and produce an output. Paint the disc in a way such that you can find the direction of rotation by looking at the output.
Paint like WWBWBB
After 2 ww, if it is BW, one direction
After 2 ww if it is BB, the other direction
Paint like WWBWBB
After 2 ww, if it is BW, one direction
After 2 ww if it is BB, the other direction
You have three baskets. Basket #1 has apples,Basket # 2 has oranges, and Basket #3 has oranges and apples. The baskets are mislabled. After how many t
You have three baskets. Basket #1 has apples,Basket # 2 has oranges, and Basket #3 has oranges and apples.
The baskets are mislabled. After how many tries will you be able to figure out which baskets have the correct items.
Basket 1, labeled A and O can contain A or O
Basket 2, labeled O can contain A or A+O
Basket 3, labeled A can contain O or A+O
Get one from basket 1, if it is apple
Basket 1, A
Basket 2, A+O
Basket 3, O
or
Get one from basket 1, if it is orange
Basket 1, O
Basket 2, A+O
Basket 3, A
The baskets are mislabled. After how many tries will you be able to figure out which baskets have the correct items.
Basket 1, labeled A and O can contain A or O
Basket 2, labeled O can contain A or A+O
Basket 3, labeled A can contain O or A+O
Get one from basket 1, if it is apple
Basket 1, A
Basket 2, A+O
Basket 3, O
or
Get one from basket 1, if it is orange
Basket 1, O
Basket 2, A+O
Basket 3, A
There are 25 horses, each one runs at constant speed and each one runs at different speed. You need to find out the minimum races it takes to find out
There are 25 horses, each one runs at constant speed and each one runs at different speed. You need to find out the minimum races it takes to find out the first, second and third fastest horses from them. Each horse race can only have 5 horses and you don't have a stop watch to time it.
First race each group which has 5 horses, take the winner of each group, and race them, then, drop the fourth and fifth horses, take the 2nd and 3rd from winner’s original group, and 2nd horse from 2nd winner’s original group, race them, get the other top 2 horses
First race each group which has 5 horses, take the winner of each group, and race them, then, drop the fourth and fifth horses, take the 2nd and 3rd from winner’s original group, and 2nd horse from 2nd winner’s original group, race them, get the other top 2 horses
8 bottles, 3 people to test, how to find one poison bottle with fast time Use binary representation, 8 bottles are from 000 to 111, 3 people are 1 2 a
8 bottles, 3 people to test, how to find one poison bottle with fast time
Use binary representation, 8 bottles are from 000 to 111, 3 people are 1 2 and 3, for each bottle, based on the binary representation, corresponding people to drink, for example, the 5th bottle is 101, use the 1 and 3 persons to drink. Then after some people die, just decode to find out which one is poison
Use binary representation, 8 bottles are from 000 to 111, 3 people are 1 2 and 3, for each bottle, based on the binary representation, corresponding people to drink, for example, the 5th bottle is 101, use the 1 and 3 persons to drink. Then after some people die, just decode to find out which one is poison
There are two people A and B, both are geographically apart from each other and can't meet. They exchange messages through a Box which has two latches
There are two people A and B, both are geographically apart from each other and can't meet. They exchange messages through a Box which has two latches and the box is delivered by a postman. Given the chance the postman will break into the box. The box can't be opened if there is at least one locked latch. Both A and B buy a lock, both get two keys with them (A has lock1 and B has lock2). Now how can they communicate securely using this system?
Suppose A has lockA and keyA, b has lockB and keyB
A put the message in box and lock the box using lockA send to B
B lock the box using lockB and send to A
A use keyA to unlock lockA, send to B
B use keyB to unlock lockB and read the message
Suppose A has lockA and keyA, b has lockB and keyB
A put the message in box and lock the box using lockA send to B
B lock the box using lockB and send to A
A use keyA to unlock lockA, send to B
B use keyB to unlock lockB and read the message
Using two cubes (12 sides) make a desk calendar that can cover all of the days of the month (01-31).
Using two cubes (12 sides) make a desk calendar that can cover all of
the days of the month (01-31).
0 1 2 3 4 5
0 1 2 6 7 8
6 can be inversed as 9
the days of the month (01-31).
0 1 2 3 4 5
0 1 2 6 7 8
6 can be inversed as 9
Suppose there are two identical cups of water. One is red, the other is green. You take out 1ml of red water and put it into the green water. Th
Suppose there are two identical cups of water. One is red, the other is
green. You take out 1ml of red water and put it into the green water.
Then you take 1ml of (mixed) green water into the red water. Does the
red water have more green or does the green have more red?
Red Green
X X
Red: x-1 red: 1, green x
Red: x-1+1/(1+x) green: x/(1+x) red: 1-1/(x+1) green: x-x/(x+1)
So they are equal
green. You take out 1ml of red water and put it into the green water.
Then you take 1ml of (mixed) green water into the red water. Does the
red water have more green or does the green have more red?
Red Green
X X
Red: x-1 red: 1, green x
Red: x-1+1/(1+x) green: x/(1+x) red: 1-1/(x+1) green: x-x/(x+1)
So they are equal
You've got someone working for you for seven days and a gold bar to pay them. The gold bar is segmented into seven connected pieces. You must give the
You've got someone working for you for seven days and a gold bar to pay
them. The gold bar is segmented into seven connected pieces. You must
give them a piece of gold at the end of every day. If you are only
allowed to make two breaks in the gold bar, how do you pay your worker?
Break the bar into 1 piece, 2 pieces and 4 pieces
Day 1: give 1 piece
Day 2:give 2 piece, get 1 piece back
Day 3: give 1 piece
Day 4: give 4 piece, get 1 piece and 2 piece back
Repeat day 1 to day 3
them. The gold bar is segmented into seven connected pieces. You must
give them a piece of gold at the end of every day. If you are only
allowed to make two breaks in the gold bar, how do you pay your worker?
Break the bar into 1 piece, 2 pieces and 4 pieces
Day 1: give 1 piece
Day 2:give 2 piece, get 1 piece back
Day 3: give 1 piece
Day 4: give 4 piece, get 1 piece and 2 piece back
Repeat day 1 to day 3
You're given a coffe can contains Black, White beans and large pile of extra black beans. You then repeat the following process until there is a singl
You're given a coffe can contains Black, White beans and large pile of extra black beans. You then repeat the following process until there is a single bean left in the can.
Randomly select two beans from the can. If they're same color throw them both out and insert an extra black bean. If they're different colors return the white bean to the can and throw out the black.
Prove that process terminates. What can you say about the color of final remaining bean as function of the number of white and black beans originally in the can?
Process terminates as you reduce the amount by one at each step.
The parity of # of white beans does not change.
So if initially there were an odd number of white beans, the final bean will be white. Else the final bean will be black.
Randomly select two beans from the can. If they're same color throw them both out and insert an extra black bean. If they're different colors return the white bean to the can and throw out the black.
Prove that process terminates. What can you say about the color of final remaining bean as function of the number of white and black beans originally in the can?
Process terminates as you reduce the amount by one at each step.
The parity of # of white beans does not change.
So if initially there were an odd number of white beans, the final bean will be white. Else the final bean will be black.
You have two identical roop. Both of them have the following properties: 1. Each burns in one hour. 2. They burn at a non-uniform rate. i.e. there is
You have two identical roop. Both of them have the following properties:
1. Each burns in one hour.
2. They burn at a non-uniform rate. i.e. there is no correlation between the length of the rope with the time it takes to burn it.
Using only these roops find out when 1.5 hrs have elapsed?
burn rope at both the end simultaneously. It’ll burn in 30 mins. when the first rope completes Then burn the other rope at one end.it ll burn in 1 hour making a total of 1.5 hrs
same two rope how to get 15 mins
first rope burns two end, the second rope burns one end, if first rope finished, stop the second rope.
Then you burn two end of second rope you can get 15 mins
1. Each burns in one hour.
2. They burn at a non-uniform rate. i.e. there is no correlation between the length of the rope with the time it takes to burn it.
Using only these roops find out when 1.5 hrs have elapsed?
burn rope at both the end simultaneously. It’ll burn in 30 mins. when the first rope completes Then burn the other rope at one end.it ll burn in 1 hour making a total of 1.5 hrs
same two rope how to get 15 mins
first rope burns two end, the second rope burns one end, if first rope finished, stop the second rope.
Then you burn two end of second rope you can get 15 mins
Dec 19, 2008
You have 10 balls out of which 8 have the same weight while two are heavy. How many comparisons you would need to find the heavier ones in the worst c
You have 10 balls out of which 8 have the same weight while two are heavy. How many comparisons you would need to find the heavier ones in the worst case.
I think that is 4 times,
Apart 10 balls into 3 sets like set1 bbb, set2 bbb, set3 bbbb
Weight set1 and set2, if not equal, we can get heavier ball in next 2 weights
If equal, the two heavier balls can be either in set3 or one in set1 and the other in set2.
Take 3 balls from set3 and weight with set1, if set1 heavier, the heavier ball should be in set1 and set2, otherwise the heavier balls should be in set3. so we can get the heavier ball in next two weights
I think that is 4 times,
Apart 10 balls into 3 sets like set1 bbb, set2 bbb, set3 bbbb
Weight set1 and set2, if not equal, we can get heavier ball in next 2 weights
If equal, the two heavier balls can be either in set3 or one in set1 and the other in set2.
Take 3 balls from set3 and weight with set1, if set1 heavier, the heavier ball should be in set1 and set2, otherwise the heavier balls should be in set3. so we can get the heavier ball in next two weights
Write an algorithm to check unsigned integer is a multiple of 3, without using division and modulo operators.
Write an algorithm to check unsigned integer is a multiple of 3, without using division and modulo operators.
Get each decimal digit from the integer number, sum up them, if they can be divisible by 3. the number is multiple of 3
Like 123456,
1+2+3+4+5+6=21
1+2=3 so 123456 can be divisible by 3.
Get each decimal digit from the integer number, sum up them, if they can be divisible by 3. the number is multiple of 3
Like 123456,
1+2+3+4+5+6=21
1+2=3 so 123456 can be divisible by 3.
Bool Foo(int num)
{
While(true)
{
num=Sum up all decimal digits of num;
If(num==3||num==6||num==9)
Return true;
If(num<3)
Return false;
}
Dec 15, 2008
find the direction of rotation for a disc
There is a blank disc( like a CD). You are given two colors of paint (black and white) . A sensor can recognize the color painted on the disc and produce an output. Paint the disc in a way such that you can find the direction of rotation by looking at the output.
Paint like WWBWBB
After 2 ww, if it is BW, one direction
After 2 ww if it is BB, the other direction
Paint like WWBWBB
After 2 ww, if it is BW, one direction
After 2 ww if it is BB, the other direction
contaminated pills problem
You have 4 jars of pills. Each pill is a certain weight, except for contaminated pills contained in one jar, where each pill is weight + 1. How could you tell which jar had the contaminated pills in just ONE measurement?
Take 1 pill from jar one, take 2 pills from jar two, take 3 from jar three, take 4 from jar four,
Put them on the measurement instrument.
If the overweight is 1 , jar one has contaminated pill
If the overweight is 2, jar two has contaminated pill
If the overweight is 3, jar three has contaminated pill
If the overweight is 4, jar four has contaminated pill
Take 1 pill from jar one, take 2 pills from jar two, take 3 from jar three, take 4 from jar four,
Put them on the measurement instrument.
If the overweight is 1 , jar one has contaminated pill
If the overweight is 2, jar two has contaminated pill
If the overweight is 3, jar three has contaminated pill
If the overweight is 4, jar four has contaminated pill
Subscribe to:
Posts (Atom)