a353532(w,h)={my(nb=2*(w+h)-4,x=vector(nb),y=vector(nb), d12,d13,d14,d23,d24,d34, dist(xa,ya,xb,yb)=(xa-xb)^2+(ya-yb)^2,L=List(),l=0); \\ x, y are the coordinates of points on the perimeter \\ of the w X h rectangle, with corners excluded. for(k=1,w-1,l++;x[l]=k;y[l]=0); for(k=1,h-1,l++;x[l]=w;y[l]=k); forstep(k=w-1,1,-1,l++;x[l]=k;y[l]=h); forstep(k=h-1,1,-1,l++;x[l]=0;y[l]=k); \\ select 4 points on the perimeter in 4 loops with \\ loop variables n1, n2, n3, n4. \\ This is very inefficient, but covers the general case of A354700, \\ where the corners of the rectangle are allowed. for(n1=1,nb-3,x1=x[n1];y1=y[n1]; for(n2=n1+1,nb-2,x2=x[n2];y2=y[n2]; d12=dist(x1,y1,x2,y2); for(n3=n2+1,nb-1,x3=x[n3];y3=y[n3]; d13=dist(x1,y1,x3,y3); \\ skip body of current loop when equal \\ distances are found if(d13==d12,next); d23=dist(x2,y2,x3,y3); if(d23==d12,next); if(d23==d13,next); for(n4=n3+1,nb,x4=x[n4];y4=y[n4]; \\ assure that the full range of the bounding rectangle is used if(vecmin([x1,x2,x3,x4])>0,next); if(vecmax([x1,x2,x3,x4])<w,next); if(vecmin([y1,y2,y3,y4])>0,next); if(vecmax([y1,y2,y3,y4])<h,next); d14=dist(x1,y1,x4,y4); if(d14==d12,next); if(d14==d13,next); if(d14==d23,next); d24=dist(x2,y2,x4,y4); if(d24==d12,next); if(d24==d13,next); if(d24==d14,next); if(d24==d23,next); d34=dist(x3,y3,x4,y4); if(d34==d12,next); if(d34==d13,next); if(d34==d14,next); if(d34==d23,next); if(d34==d24,next); \\ add negative lengths of diagonals to the set of 6 distinct distances \\ to cope with ambiguous cases where the allocation of \\ lengths is not unique my(t=Set([d12,d13,d14,d23,d24,d34,-d13,-d24])); \\ append enhanced distance set to list listput(~L,t))))); \\ replace previous line by the following line to get diagnostic \\ output with vertex coordinates of quadrilateral. \\ Only suitable for small parameters, e.g. (w,d)=(3,1),(3,2),(3,3),(4,1),... \\ listput(~L,t); print([x1,y1,x2,y2,x3,y3,x4,y4],t))))); \\ Result: cardinality of the set of enhanced distance sets #Set(L)};