<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="IncrediMail 1.0" name=GENERATOR></HEAD>
<BODY style="BACKGROUND-POSITION: 0px 0px; FONT-SIZE: 12pt; MARGIN: 5px 10px 10px; FONT-FAMILY: Arial" bgColor=#ffffff background="" scroll=yes ORGYPOS="0">
<TABLE id=INCREDIMAINTABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD id=INCREDITEXTREGION style="FONT-SIZE: 12pt; CURSOR: auto; FONT-FAMILY: Arial" width="100%">
<DIV> </DIV>
<DIV> </DIV>
<DIV id=receivestrings>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>From:</B></I> <A href="mailto:nospam@me.invalid">anthonyberet</A></DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>Date:</B></I> 02/18/06 17:11:01</DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>To:</B></I> <A href="mailto:python-list@python.org">python-list@python.org</A></DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>Subject:</B></I> Re: 2-dimensional data structures</DIV></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>I am not sure how to most efficiently identify which region any given</DIV>
<DIV>square on the grid is actually in - any thoughts, for those that have</DIV>
<DIV>done this? - I don't want a massive list of IF conditionals if I can</DIV>
<DIV>avoid it.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Kermit says:</DIV>
<DIV> </DIV>
<DIV>There is a MUCH more efficient way to do this!</DIV>
<DIV> </DIV>
<DIV>If you are doing a 9 by 9 soduku,</DIV>
<DIV> </DIV>
<DIV>Each row and column has exactly the digits 1 through 9</DIV>
<DIV> </DIV>
<DIV>Think of your data as being in a list 81 cells long that is accessed 3 different ways.</DIV>
<DIV> </DIV>
<DIV>As a 9 by 9, row wise,</DIV>
<DIV> </DIV>
<DIV>As a 9 by 9 column wise</DIV>
<DIV> </DIV>
<DIV>As a 3 by 3 by 9 where the first two subscripts identify the region, and the last identify one of</DIV>
<DIV>the 9 values within the region.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>And , most important,</DIV>
<DIV> </DIV>
<DIV>To search for a value not yet in a row, column, or region,</DIV>
<DIV> </DIV>
<DIV>Define holding list of length 9.</DIV>
<DIV> </DIV>
<DIV>Suppose a row has 4,2,8 in it,</DIV>
<DIV> </DIV>
<DIV>and the corresponding column has 2,3,1 in it</DIV>
<DIV> </DIV>
<DIV>and the correspond region has 2, 7, 6 in it.</DIV>
<DIV> </DIV>
<DIV>Then you initialize your hold vector to -1,</DIV>
<DIV> </DIV>
<DIV>and set</DIV>
<DIV> </DIV>
<DIV>hold(4) = 4</DIV>
<DIV>hold(2) = 1</DIV>
<DIV>hold(8) = 1</DIV>
<DIV>hold(2) = 1</DIV>
<DIV>hold (3) = 1</DIV>
<DIV>hold(1) = 1</DIV>
<DIV>hold(2) = 1</DIV>
<DIV>hold(7) = 1</DIV>
<DIV>hold(6) = 1</DIV>
<DIV> </DIV>
<DIV>Then by scaning only the nine elements of hold, you see that</DIV>
<DIV> </DIV>
<DIV>hold(5) = -1, , and hold(9) = -1 are the only values not reset, and </DIV>
<DIV> </DIV>
<DIV>only 5 and 9 are possible choices for the target cell.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV></TD></TR>
<TR>
<TD id=INCREDIFOOTER width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD width="100%"></TD>
<TD id=INCREDISOUND vAlign=bottom align=middle></TD>
<TD id=INCREDIANIM vAlign=bottom align=middle></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BODY></HTML>