A Computer Program for Nim Multiplication T. S. Ferguson In my book, ``A Course in Game Theory'', it is shown how to compute nim multiplication of any two nonnegative integers. Here is a subroutine written in C that will compute that product provided both integers are less than F_4=65536. (Here, F_n = 2^{2^n} is the nth Fermat 2-power.) int prod(int x,int y) { int F,i,t; if (x>y) {t=x;x=y;y=t;} //Now x<=y if (x==0) {return 0;} //Now x>=1 if (x==1) {return y;} //Now x>=2 if (y==2) {return 3;} //Now y>=3 if (y==3) {return (x==2)? 1:2;} //Now y>=4 F=4; //Fermat 2-power do { if (y==F) {return (x b, x = b; y = a, x = a; y = b]; If[x == 0, Return[0]]; If[x == 1, Return[y]]; If[y == 2, Return[3]]; If[y == 3, If[x==2,Return 1,Return 2]]; For[F = 4, True, F = F*F, If[y == F, If[x < y, Return[x*y], Return[3*(y/2)]]]; If[y < 2*F, Return[sum[prod[F, x], prod[y - F, x]]]]; For[t = 2*F, t < F*F, t = 2*t, If[y == t, If[x < F, Return[prod[prod[x, t/F], F]]]; For[i = F, i < t, i = 2*i, If[x == i, Return[prod[prod[F, F], prod[t/F, i/F]]]]; If[x < 2*i, Return[sum[prod[t, i], prod[t, x - i]]]]; ]; If[x == t, Return[prod[prod[F, F], prod[t/F, t/F]]]]; ]; If[y < 2*t, Return[sum[prod[t, x], prod[y - t, x]]]]; ]; ]; ]