📜 ⬆️ ⬇️

Lost in translation: when 2 * 2 = 5

Imagine: your nephew asks you how much will be 2 * 2 + 1. You don’t have to, and you forward the question to your interpreter, who honestly answers: 6. Attention, question: thanks to what programming language will your nephew get a deuce tomorrow?

The correct answer is j . In this language, verbs (any actions on data, including arithmetic operations) have no priority and are executed from right to left in the absence of brackets. Thus, the query 2 * 2 + 1 is equivalent to the unusual for most of us (2 * 2) +1, and 2 * (2 + 1).

PS I suspect and almost sure that there are more than one language with violations of the traditional priority of arithmetic operations, but with others it has not yet been possible to deal with.

')

Source: https://habr.com/ru/post/94010/


All Articles