# Find the direction of the disc

You have a disc. One half of the disc is painted white and the other half is black. The disc rotates in either a clockwise direction or an anti-clockwise direction.

There are two sensors which are not connected to the disc but are in a fixed position, pointed at the disc. They are at 90° from each other with respect to the center of the disc. The sensors output the value 1 when reading white and 0 when reading black.

Using only the output of the two sensors, find the direction in which the disc is rotating.

• This question was asked me in an interview, where I had to draw a circuit to find a direction. Here, I have modified this question. Nov 19 '15 at 11:38
• So what are we allowed to do? Can we touch the disk? Spin the disk? Paint the disk? Nov 19 '15 at 11:46
• No, you can't touch the disc. The disc is already rotating. and it is already painted with Black and White color. You just need to figure out the direction of the disc from the output of the sensors. Nov 19 '15 at 11:51
• In addition, when the sensor detects a black color, it gives a value "0" and when it detects a white color, it gives a value "1". Nov 19 '15 at 11:57
• At the 90° from the center of the disc; meaning they are 180° apart or only 90°?
– Jens
Nov 19 '15 at 12:00

There are four possible initial states for the sensor. There are two possible changes, one for clockwise, one for counter clockwise.

The disc is rotating clockwise if Sensor 1 changes to the value of Sensor 2 and Sensor 2 becomes Sensor 1 XOR 1

The disc is rotating counter clockwise if Sensor 1 changes to the value of Sensor 2 XOR 1 and Sensor 2 becomes Sensor 1.

• Yes... perfect..!! 😀 Nov 19 '15 at 12:25
• I gave the similar answer with the same truth table in my interview... but I took almost 20-25 minutes to solve it...!! Nov 19 '15 at 13:01

So if I'm getting this correct, we have a disc with radius R at the origin, and a sensor at (-R,0) and (0,R). The disc is half black, half white, with the dividing line between the colors being a straight line going through the center of the disc.

If both sensors show 1, we know the black part of the disc is up. Then if the left sensor goes to 0 before the other one, we know the disc is rotating clockwise. If the right sensor goes out first the disc is rotating counter-clockwise.

If the sensors are 180 degrees apart, (-R,0) and (R,0), I don't believe this is solvable without because you're unable to distinguish between clockwise with black side up and counterclockwise with black side down.

• My guess as well, can't figure out a way to do it with the sensors being 180° apart.
– Jens
Nov 19 '15 at 12:11
• Good imagination without a diagram...!! Nov 19 '15 at 12:58
• @H.Modh Thanks, Would've given a table to if i knew that was the goal ;) Nov 19 '15 at 13:05
• @DrunkWolf... It is possible that the interviewer was looking for an answer without a table... like yours... Nov 19 '15 at 13:07