31 Aug
2013
31 Aug
'13
7:54 p.m.
On 31/08/2013 12:58, Mike Speciner wrote:
def f(x,n) : return x^(x>>n);
def g(x,n) : while x>>n : x ^= x>>n; n*=2; return x;
[quad:]
Given a 32-bit unsigned integer x, and a positive integer n, let ... a = x ^ (x >> n)
find, if one exists, a function f such that f(a) = x. In other words, invert the operation on x, or show otherwise.
It may be worth observing that (modulo implementation details) Mike's solution (*the* solution) is essentially the same thing as 1 / (1+x^n) = 1 - x^n + x^2n - x^3n ..., where (mod 2) minus equals plus. -- g