I had a logical riddle on a programming interview test which was something like this:
In his garage a millionaire had cars, of which only 2 were not white, only 2 were not green and only 2 were not red. How many cars did the millionaire have in his garage?
This seamed quite straightforward to me and I gave an answer, however I wasn't allowed to see my test afterwards and I cannot tell if the answer is correct.
I am curious to see if my answer was correct and also if there is a better mathematical derivation to the problem.
Answer
A total of
three
cars, with colors distributed such that
one is red, one is green, and one is white.
If you take white, then all cars except two (green and red) are white. Likewise, if you take red, all cars except two (white and green) are red. And if you take green, all cars except two (red and white) are green.
Reasoning for this conclusion
If there are more, then the statement that "of them two are not white/green/red" will fail.
Let the total number of cars be $n$
Total number of white cars be $x$
Total number of green cars be $y$
Total number of red cars be $z$
Then $$2 = n-x \rightarrow x = n-2$$ $$2 = n-y \rightarrow y = n-2$$ $$2 = n-z \rightarrow z = n-2$$
So $$n = x+y+z$$ $$n = (n-2) + (n-2) + (n-2) $$ $$n = 3n - 6$$ $$6 = 2n $$
Thus,
n = 3
Note
As far as what I understood from the question "of which only 2 were not white" means there is at least one white car and definitely more than 2 cars. The same for all colors specified in the question. Otherwise the questioner should have mentioned "of which 2 were not white" or "2 cars were not white" or just "none of them are white" instead.
No comments:
Post a Comment