Brain teaser: A more complicated way to negate integers
Today, we will look at a brain teaser:
Design a function f() that operates on whole numbers, such that f(x) = y and f(y) = -x. Or, more succintly, f(f(x)) = -x.
I will help you analyze the problem, and contribute my suggestion for a solution, along with an explanation of why it works.
Spoiler warning! You WILL learn an answer to this question. If you want a challenge, attempt to solve the problem before reading the rest of the post 🙂
Recent Comments