\\ Auxiliary functions inrot and inrotd: \\ points (x,y) on the boundary are counted as outside; \\ this is a conservative choice for the maximization of covered grid points inrot(x,y,w,h,sp,cp) = {my (xr=x*cp+y*sp, yr=-x*sp+y*cp); xr>0 && xr 0 && yrcmax, disming=0; cmax=n ); \\ for the current maximum number of covered grid points n \\ try to find configurations maximizing the minimum distance of any grid point \\ from the perimeter of the covering rectangle if ( n>=cmax, my (dismin=oo); for( x = -limit, limit, for( y = -1, limit, xx=x+dx; yy=y+dy; if ( inrot( xx, yy, w, h, sp, cp), dismin = min ( dismin, inrotd (xx, yy, w, h, sp, cp) ) ) ) ); \\ Output in case of improvement \\ n ... covered grid points \\ dx, dy ... translation of cover \\ phi ... rotation angle of cover \\ ratslope ... rational approximation of slope \\ dismin ... distance margin to boundary if ( dismin > disming, disming = dismin; ratslope = bestappr(tan(phi),2*limit); print ([n, dx, dy, phi, ratslope, dismin]) ) ) ); [cmax, ratslope] }; \\ Examples of calls \\ a355244(4,2,100000) should return 10 covered grid points and slope either 3 or 1/3 \\ a355244(12,4) 52 covered points and slope 13/14 or similar - don't be too impatient, it may take a while \\ a355244(12,4,,1) will not find more than 51 points