Re:[Stack Overflow]Design a function f, such that f(f(n)) ==...
by pfortuny on Tuesday June 25, 2013 @08:49AM
(#5939028)
I guess you do not understand my formula...
Given z a non-zero integer, either z=2n or z=2n-1 or z=-2n or z=-(2n-1), for some natural n>0... f(n) is defined according to each case. Uhu? And AFAIK f(f(n))=-n.
This should not be too hard to express in 32 bit arithmetic. With bitwise shifts etc.
2) You can't just do an operation to the right side and then do the inverse inside of the function on the left side. It has to be done outside of the function.
3) You didn't accomplish anything with your butchered math. We wanted f(f(n)) = -n