Re:[Stack Overflow]Design a function f, such that f(f(n)) ==...
by richardkiss on Friday June 28, 2013 @01:20AM
(#5956412)
f(f(n)) = n^2 is actually easy when you consider it restricted to 32-bit signed integers. Since it's impossible to make it work for any abs(n)>65536 (it's too big), you can reserve all those values as intermediate stopover points for the ones it WILL work for.
f(n)
= abs(n) + 65536 if n < 65536
= unsigned32(n & 0xffff) ** 2 if n >= 65536
f(n)
Cheeky, eh?