[math-fun] errors by WDS corrected
arggh, sorry for my incorrect word bit-reversal hack. It was "so obviously correct, I did not need to test it." Famous last words... ---------- Also, in my "Knight distance" post, I made this minor error: (7,7) was actually correctly handled by my formula, and did not need to be an exception. Apparently the only exceptions are (0,1) and (2,2). Here is C-language code -- which I now actually did test -- for Knight distance where dx = abs(x2-x1), dy=abs(y2-y1). It is conjecturally correct for all integers, but it is proven correct only for the finite set tested (i.e. an 8x8 chessboard): Ki = max(dx,dy); L1 = dx+dy; if(Ki<3){ if(L1==1){ return(3); } if(L1==4){ return(4); } //omit next line if bi-infinite chessboard: if( (InCorner(a) || InCorner(b)) && dx==1 && dy==1 ){ return(4); } } if(L1 & 1){ //different square colors, so KnightDist=odd F = ( 4+max(2*L1, 3*Ki) ) / 12; F *= 2; F++; //divide rounds downward }else{ //KnightDist=even F = ( 10+max(2*L1, 3*Ki) ) / 12; F *= 2; //divide rounds downward } return(F); //knight distance It is rather annoying that I do not have a proof of correctness. One would think there would be trivial inductive demonstration, where the base case is the fact it works when L1<50, or whatever. -- Warren D. Smith http://RangeVoting.org
="Warren D Smith" <warren.wds@gmail.com> arggh, sorry for my incorrect word bit-reversal hack. It was "so obviously correct, I did not need to test it." Famous last words...
"Beware of bugs in the above code; I have only proved it correct, not tried it." --Don Knuth Likewise, sorry for any errors in the knight stuff--I think I originally worked it out by hand on graph paper back in the 90's...YMMV...corrections to the OEIS are of course most welcome!
participants (2)
-
Marc LeBrun -
Warren D Smith