I tried tackling the problem numerically. I found that up to 13 layers of depth(the furthest I could go), there was no solution. First I inverted
$ f(x) = 2x+1 -> f^{-1}(x) = \frac{x-1}{2}$
$ g(x) = \frac{x}{x+2} -> g^{-1}(x) = \frac{2x}{1-x}$
Next, I want to consider all possible inversions of 2016 at a depth n. The question we are trying to answer:
is
$ h_1 ( h_2 ( h_3 ( h_4 ( h_5 ... h_n (2016 ))))))) \in \Z $
Where $h_i$ is either $f^{-1}(x)$ or $g^{-1}(x)$.
What I did was considered all possible permutations of $f^{-1}$ and $g^{-1}$, and I find that up to n=13 there is no solution. That is, there is no integer which application of f(x) and g(x) reaches the value 2016.
for instance
$f^{-1}(2016) = 1007.5$
$g^{-1}(2016) = -2.00099$
$f^{-1}(f^{-1}(2016))=503.25$
$g^{-1}(f^{-1}(2016))=-2.00199$
$f^{-1}(g^{-1}(2016))=-1.5005$
$g^{-1}(g^{-1}(2016))=-1.33355$
code:
#include <stdio.h>
double finverse(double x)
{
return (x-1)/2;
}
double ginverse(double x)
{
return 2 * x/(1-x);
}
void printBits(size_t const size, void const * const ptr)
{
unsigned char *b = (unsigned char*) ptr;
unsigned char byte;
int i, j;
for (i=size-1;i>=0;i--)
{
for (j=7;j>=0;j--)
{
byte = b[i] & (1<<j);
byte >>= j;
printf("%u", byte);
}
}
puts("");
}
int main(int argc, char **argv)
{
int num = 1;
int index;
double *previous = malloc(sizeof(double));
*previous = 2016;
double *current;
for(num=1;num<10;num++)
{
printf("Depth is %d\n",num);
current = malloc((int)pow(2,num)*sizeof(int));
for(index=0;index<pow(2,num);index++)
{
//printf("Index is %d\n",index);
if(index %2 == 0)
*(current + index) = finverse(*(previous+index/2));
else
*(current + index) = ginverse(*(previous+index/2));
printf("Value is %g\n",*(current+index));
if(*(current+index) == (int)(*(current+index)))
{
printf("\n\n\n\SOLUTION HAS BEEN FOUND\n\n\n");
printf("%g ",*(current+index));
printBits(sizeof(int),&index);
printf("\n");
}
}
previous = current;
}
}