need a function

Brendan McKay bdm at cs.anu.edu.au
Sat Jun 14 11:43:45 CEST 2008


Looking great!  Brendan.

* Andrew Weimholt <andrew at weimholt.com> [080614 19:41]:
> Here's a more elegant solution...
> 
> break up the desired value of f(x) into bits, a,b,c,d,e such that
> 
> f(x) = 16 * e(x) + 8 * d(x) + 4 * c(x) + 2 * b(x) + a(x)
> 
> a(x) = (x % 3)/2
> b(x) = (x % 5)/3
> c(x) = (x % 17)/9
> d(x) = (x % 257)/129
> e(x) = (x % 65537)/32769
> 
> So we have
> 
> f(x) = 16 * ((x % 65537)/32769) + 8 * ((x % 257)/129) + 4 * ((x % 17)/9)
>      + 2 * ((x % 5)/3) + (x % 3)/2
> 
> replacing x % n with x - n(x/n), we get...
> 
> f(x) = 16((x - 65537(x/65537))/32769) + 8((x - 257(x/257))/129)  +
>     4((x - 17(x/17))/9) + 2((x - 5(x/5))/3) + (x - 3(x/3))/2
> 
> Andrew





More information about the SeqFan mailing list