Confessions of a code junkie
 
Monday, May 19, 2008

Programming Job Interview Challenge #4 Answer
 
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 kick it on DotNetKicks.com   Comments [0] -
Tags: Stuff


Comments are closed.
 


All Content © 2008, Jon von Gillern
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.


 


Tags

Archive

Blogroll