Programmers are expected to be good at logical thinking because computers are logical machines. Logical thinking puzzles challenge and entertain those who attempt them, and also help shape the thought process. This article is a dynamic collection of logical puzzles to which puzzles will be periodically added.
Puzzle #1:
Answer:
The wise man advises that they swap the camels and race!
The camel that is fastest is bound to lose, but the camel rider is bound to win as he is riding the opponent’s camel!
There are situations in programming where we cannot directly solve the problem given to us, but can solve the opposite kind of problem, and there exists a procedure to convert the problem to it’s opposite type! For example, given access to a max() function in C that returns the maximum of 2 values, we can use the function to find the minimum of 2 values as follows:
min = a==max(a,b) ? b : a;
Perhaps the most well-known and frequently used application of this is De Morgan’s Laws in Boolean Algebra:
1. not (A and B) = (not A) or (not B)
2. not (A or B) = (not A) and (not B)
Thus, if we can “AND” but don’t want to “OR”, we can convert “OR” problems into “AND” problems and then solve them!
Puzzle #2:
Answer:
Since the bridge is 4 kilometers long, the halfway point would be 2 kilometers. The 18-wheeler would have used much more than 30g of fuel to drive 2 kilometers.
This logical puzzle takes advantage of our wrong assumption that the weight of something (in this case, the truck), once declared, remains unchanged with time!
Related Articles
19 users responded in this post