|
SmtC: Show me the Code
Ole Peter Smith
Instituto de Matemática e Estatística
Universidade Federal de Goiás
http://www.olesmith.com.br
|
|
Deus não se preocupe das nossas dificuldades matemáticas.
Ele integra empiricamente.
Einstein.
|
Values that Appears once in Row, Column of Box Values (Topologies)
Python Listing: ../Incidence.py.
class Sudoku_Topology_Incidence(
):
def Topology_Incidence_Apply(self,topology):
musts=self.Topology_Incidence(topology)
texts=[]
for must in musts:
r=must[0]
s=must[1]
value=must[2]
descriptor=must[3]
self.S[r][s]=value
texts.append("S["+str(r)+","+str(s)+"]="+str(value)+" "+descriptor)
if (len(musts)>0):
print "Setting by Incidence:\n\t"+"\n\t".join(texts)
else:
print "No more by Incidence"
topology=self.Topology_Initial()
return musts
def Topology_Incidence(self,topology):
musts=[]
musts=musts+self.Topology_Incidence_Rows(topology)
musts=musts+self.Topology_Incidence_Columns(topology)
musts=musts+self.Topology_Incidence_Boxes(topology)
musts_dict={}
rmusts=[]
for must in musts:
key=str(must[0])+"_"+str(must[1])
if (not musts_dict.has_key(key)):
rmusts.append(must)
musts_dict[ key ]=True
return rmusts
def Topology_Incidence_Rows(self,topology):
musts=[]
for r in range(self.M):
musts=musts+self.Topology_Incidence_Elements(
topology,
self.Sudoku_Row(r),
"R"+str(r+1)
)
return musts
def Topology_Incidence_Columns(self,topology):
musts=[]
for s in range(self.M):
musts=musts+self.Topology_Incidence_Elements(
topology,
self.Sudoku_Column(s),
"C"+str(s+1)
)
return musts
def Topology_Incidence_Boxes(self,topology):
musts=[]
for rr in range(self.N):
for ss in range(self.N):
musts=musts+self.Topology_Incidence_Elements(
topology,
self.Sudoku_Box(rr,ss),
"B"+str(rr+1)+""+str(ss+1)
)
return musts
def Topology_Incidence_Elements(self,topology,elements,descriptor):
values=set()
for element in elements:
r=element[0]
s=element[1]
if (self.S[r][s]==0):
for value in topology[r][s]:
values.add(value)
musts=[]
for value in values:
n=0
rr=ss=-1
for element in elements:
r=element[0]
s=element[1]
if (self.S[r][s]==0):
if (value in topology[r][s]):
n+=1
rr=r
ss=s
#Unique
if (n==1):
musts.append([rr,ss,value,descriptor])
return musts
|
|
Messages:
0 secs.
|