4 ms·
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 b
by richardkiss 13y ago
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
Cheeky, eh?
- pfortuny 13y agoAh, yes. But I was thinking of all the integers. I know, I should have read the OP but I was too lazy. Really cheeky, though :)