Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I get 5 or 7 and if i get 5 i need to return 7 if i get 7 i need to return 5.

i need to do this in 1 mathematical formula.

I have those:

12 - x

35 / x

There are more solutions ?

Example in code:

public static int Transform(int x)
    return (12-x);
    //return (35/x);
share|cite|improve this question

closed as not a real question by Aryabhata, J. M., Zev Chonoles, Henry, Ross Millikan May 11 '11 at 17:18

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

There are infinitely many more... – Aryabhata May 11 '11 at 15:51
Example: $\sqrt{74 - x^2}$. This can be easily generalized. – Aryabhata May 11 '11 at 15:53
Why are you unsatisfied with the simple ones you already have? – J. M. May 11 '11 at 15:57
@Danpe, this isn't a puzzle site. – quanta May 11 '11 at 16:02
If $h$ is an invertible function we can define $f(x) = h^{-1}(h(5) + h(7) - h(x))$. This $f$ has the property that you want. This covers the two methods you have (with $h(x)=x$ and $h(x)=\log(x)$, respectively, and quite a few more. – Thomas Andrews May 11 '11 at 16:08

return x ^ 2;

Are you sure you aren't missing any constraints?

share|cite|improve this answer
This doesn't return 5 when x is 7...nor does it return 7 when x is 5 – Nicolas Villanueva May 11 '11 at 16:12
He was using Java or C++ in his original question; ^ is a bitwise XOR. A test confirms that x^2 swaps both 5 and 7 in Visual C++ 10.0. – Michael Burge May 11 '11 at 16:20
A way to verify this answer: $2 = 5\ \text{XOR}\ 7$. (So basically return x ^ (5 ^ 7);) – Aryabhata May 11 '11 at 16:25
Woops, my bad. I was naively thinking exponentiation. – Nicolas Villanueva May 11 '11 at 16:30
yeah, I read it as exponentiation, too. You might want to make it clear in the answer that it is a bitwise operator. (Mathematicians tend to not think of bitwise operators as "mathematical formulas" as a rule.) – Thomas Andrews May 11 '11 at 16:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.