WAIT, not so fast there you cattle rustlers!!! There's a caveat: no iterations, no looping, no recursion, no tables, no lists, nor any such devices which renders the problem absurdly simple. Also, this would for "pure" integers not the java primitive, so for java we would need to include any BigInteger if that makes any difference.
I've been attempting to solve this, but a mathematician I amn't. At first glance, it looked so simple, but I started working on it and everything I have tried has failed.
It's apparent to me--yet may seem foolish to you--the best way to start is to find the mathematical expression that solves the following sequence:
1, 3, 7, 15, 31, 63, 127, 255, 511, 1023...
You can establish this pattern by starting with 1 (n0) and taking the binary sequence element at n+1 and summing them together. The first element of this sequence is 1. The second element is 3 (first element of this sequence plus second element of the binary sequence, which is two). The third element is 7 (the second element of this sequence, three, plus the third element of the binary sequence, four) on into infinity.
So the expression needs to work something like this:
any number less than 2 and greater than or equal to 0 will return 1 and...
any number less than 4 and greater than or equal to 2 will return 2 and...
any number less than 8 and greater than or equal to 4 will return 3 and...
so on and so forth.
The solution would be a Java expression that could produce the following examples:
If there's any math persons out there cringing at my naive attempts to explain and constrain the problem. You have my apologies. Also, if the underlying class utilizes any recursive or iterative techniques that's ok, like I'm sure many of the java.lang.Math functions use iterations of some sort, but that's fine. There just can't be anything like that in the solution expression.