Over at Dev102, they are running a weekly series of programming job interview questions. Here is this week’s question:
How would you implement the following method: Foo(7) = 17 and Foo(17) = 7. Any other input to that method is not defined so you can return anything you want. Just follow those rules:
- Conditional statements (if, switch, …) are not allowed.
- Usage of containers (hash tables, arrays, …) are not allowed.
And here is a one-liner that gives the correct answer. There are probably other answers, but this is a simple and fast solution to the problem.
private int Foo(int x)
{
return (x + 10) % 20;
}

May 26th, 2008 at 4:25 am
[…] for Ngu Soon Hui , Jendrik Illner, Keith Rousseau, Honest Illusion and Jon von Gillern (Loved that highlight text to reveal the answer you did!) […]