Here is a question. Can someone figure out the answer?
Maximum two “if” tests are allowed!
Given numbers from 1 to 100
If this number is divisble by 21 print "foobar"
If this number is divisble by 7 print "bar"
If this number is divisble by 3 print "foo"
If none of the above, print the number
Only one number should be printed. For example, number 21 should only print “foobar”, not all “foobar”, “bar”, “foo”.
Can be done in any language.
Many thanks.
The trick is that realising of the 4 ifs in your question, we can infer the top and bottom ones based on the middle 2.