SocraticDev logo

Foolproof Algorithm

Thursday April 2nd 2020 by SocraticDev

Programming is establishing a complex path where, no matter what information flows through it, the executed program accomplishes the desired functionalities. Otherwise it's a bug to fix!

These 'complex paths' are named algorithms. An algorithm is like a recipe: a well-defined sequence of operations with specific ingredients which almost guarantees success.

Imagine we are lost in an unknown countryside and we want to reach the nearest town. We meet two brothers at a crossroads. One is known to tell the truth every time while the other is an absolute liar. But we don't know, of the two, who is the truthful and who is the liar. We are immediately tempted to tackle the insoluble problem of determining which one will tell us the truth.

It's in vain!

There is a foolproof algorithm to get directions to the nearest town:

Just ask each of the brothers: "If I asked your brother for directions to the nearest town, what would he tell me?"

And take the opposite direction.