Rules are simple. Write an obfuscated function in any language that takes in an integer and returns the same integer. Try to use math tricks and not language tricks. IE. Try to make your function portable.
I chose English.
- Ask someone to tell me a number between 1 and 100.
- Locate a stranger and ask stranger to guess a number between 1 and 100.
- If the guess is not the same as the original number, go to step 2.
Chances are people will not only fail to figure out what I'm trying to accomplish, but they'll even question whether I myself know what I'm doing. Top that. :)
public int dsaiufgbysaukldf(int UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf)
{
int UYigvuygBUYgb78btI76Rcr651VUytrOVBGUvuftgdsf= 3;
int UYigvuygBUYgb78btl76Rcr651VUytr0VBGUvuftgdsf= 12;
UYigvuygBUYgb78btl76Rcr651VUytr0VBGUvuftgdsf = UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf* UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf% UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf;
return UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf;
}
I could do better, but you got the idea...
C#
static int Identity(int val)
{
if (val != 3547247 && val != 8224772)
return val;
return new Random(val).Next(0, 10000000);
}
def mystery_converter(x):
''' BEWARE THE POWER! '''
secret_sauce = int('0x7cb',16)
mysterious_1 = sum(ord(s) for s in "Jon Skeet")
mysterious_2 = sum(ord(s) for s in "Chuck Norris")
return x + secret_sauce - (mysterious_1 | mysterious_2)
def f(i):
d = lambda x: [(n, max(e for e in xrange(len(bin(x)) - 2) if not x % n ** e))
for n in xrange(2, x / 2 + 1)
if not x % n and d(n) == [(n, 1)]] or [(x, 1)]
return reduce(lambda x, y: x * y[0] ** y[1], d(abs(i)), i and i / abs(i))
Who's the first to explain what happens here?
Edit: Okay, here's the rundown.
The function d(x)
conducts a prime factorization of the number x
. It does so by finding all numbers from 2
to x/2
that divide x. If there's none, x
is prime, and d(x)
returns [(x,1)]
, i.e. x
1
.
All found divisors n
are checked for primarity (by recursively calling d(n)
). If n
is prime, the maximal exponent e
such that n
e
divides x
is searched for.
An upper bound for e
is floor(log
2
(x))
, which happens to be one less than the length of the binary representation of x
, hence the "len(bin(x)) - 2
" part (the function bin()
prepends "0b"
).
(n, e)
is then part of the result list, meaning n
e
.
The main part of f(i)
uses d
to get the prime factorization of abs(i)
, and then uses reduce
to multiply the resulting prime powers, starting with an initial value of "i and i / abs(i)
", which means -1
, 0
, or 1
depending on the sign of i
.
The extra handling of non-positive numbers is not strictly necessary, because d(-24) == [(-24, 1)]
would do the right thing. But then again, that's boring, because we'd more or less just be passing around the value of i
. Also, who's looking for neccessity in this question?
static string GetOriginalNumber(string inputNumber)
{
inputNumber.Replace("1","2").Trim().Concat("A man a pan a panama").Replace("A man","panama").Replace("panama","42");
//By the magic of constant strings, I give you the original number!
return inputNumber;
}
I know, not terribly creative. shrug.
private object StackOverFlow1195337(int a)
{
int r;
int z;
int p;
int t;
int x;
const int c = 4;
const int d = 2;
r = a;
z = (a + c);
r += 1 + ((a + c) + (a + d));
p = (a + d);
t = z + p;
x += t - p + (r + a) - (a + a + a);
r = ((a + t + 1) / (r - ((z + p) - t))) * (a * (0.5 + (2 * 0.25) + (x * (x - x))));
return r;
}