So one of the guys over at dev102.com has been posting job interview questions. While the most recent isn't the best interview question in the world, I thought I'd share the answer if anyone is interested.

Here is the 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.

The answer is crazy simple. Highlight the text below to reveal the answer.

public int Foo(int x)
{
    return -1 * x + 24;
}

My Algebra teacher would be so proud.


Monday, May 19, 2008 - 12:48 PM CST - Permalink - Comments [0]
Tags: Stuff


Comments are closed.
Nitriq is a Code Analysis Tool for .Net Developers. It helps you visualize your code and quickly find types and methods that need refactoring.
It is currently in a free public beta, but will have reasonable prices once the bugs are worked out.
I'll be using this blog to talk about .Net, C#, WPF, ASP.NET, Nitriq and MicroISVs.


RSS
Tags

Archive



Download   |   Documentation   |   Instructions   |   Support   |   Blog   |   About