Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

Translating rownr/colnr to boxnr/cellnr within box

 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku
View previous topic :: View next topic  
Author Message
evert

Joined: 30 Aug 2005
Posts: 68
:
Location: Amsterdam

Items
PostPosted: Mon Nov 28, 2005 10:57 pm    Post subject: Translating rownr/colnr to boxnr/cellnr within box Reply with quote

I just found out that the function that translates rownrs/colnrs into
boxnrs/cellnrs inverts itself:

Code:

function Trfi(i, j : integer) : integer;
begin
  result := (((i - 1) div 3) * 3) + ((j - 1) div 3) + 1;
end;
function Trfj(i, j : integer) : integer;
begin
  result := (((i - 1) mod 3) * 3) + ((j - 1) mod 3) + 1;
end;
//  boxnr   := Trfi(rownr,colnr);
//  bcellnr := Trfj(rownr,colnr);
//  rownr   := Trfi(boxnr,bcellnr);
//  colnr   := Trfj(boxnr,bcellnr);
Back to top
View user's profile Send private message Send e-mail
xyzzy

Joined: 24 Aug 2005
Posts: 80
:

Items
PostPosted: Tue Nov 29, 2005 1:59 am    Post subject: Reply with quote

Of course it's faster to use a lookup-table. Integer division and modulus by non-powers of two are the slowest operations on modern CPUs. It's still interesting that you can use the same lookup tables for both directions.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron