# HG changeset patch # User Henry S. Thompson # Date 1585076253 0 # Node ID a7a10e40b344844ef64829d84b9f5856e217c88b # Parent 22b0894c0f4cdbf14abfb1a7e66138fe6432a996 5a working after obvious bugfix, indenting debug print, 10a inf. loop diff -r 22b0894c0f4c -r a7a10e40b344 nono.py --- a/nono.py Sun Mar 22 18:15:42 2020 +0000 +++ b/nono.py Tue Mar 24 18:57:33 2020 +0000 @@ -108,13 +108,17 @@ dprint('s2',i-1,j) if j is not None: # Only if we actually added a blob at some point + dpush('b_s2') self.checkNew(i-1) + dpop('b_s2') elif self[i].val is True and maybeSeq is None: dprint('s3',i) maybeSeq=i dprint('s4',inSeq,i) if inSeq is not None: + dpush('b_s4') self.checkNew(i) + dpop('b_s4') return changed def onepass(self,i0,iBound,scratch,stack): @@ -266,18 +270,19 @@ self.resetAllRuns() def marginal(self,rng,l): - dprint('m',rng.start,rng.stop,rng.step) + dprint('m%s'%self.cLet,rng.start,rng.stop,rng.step,l) g=0 # length of a gap for i in rng: if self[i].val is True: - # Should//n't be possible? + # Shouldn't be possible? dprint('mx0') return False if self[i].val is False: if g>0: # Block a too-small gap - for i in (i-g,i): - self.newX(i,True) + dprint('m1',i-g,i) + for j in range(i-g,i): + self.newX(j,True) g=0 else: # None @@ -288,7 +293,8 @@ return False if g>0: # Block a too-small gap - for j in (i-g,i): + dprint('m2',i-g,i) + for j in range(i+1-g,i+1): self.newX(j,True) return True @@ -347,13 +353,17 @@ def newBlob(self,x,crossCheck=False): self[x].setVal(True) if crossCheck: + dpush('b_cc') self[x].column.checkNew(self.y) + dpop('b_cc') def newX(self,x,crossCheck=False): dprint('nx %s%s@%s'%('R',self.y,x)) self[x].setVal(False) if crossCheck: + dpush('x_cc') self[x].column.checkX(self.y,x) + dpop('x_cc') class Column(Vector): cLet='C' @@ -396,13 +406,17 @@ def newBlob(self,y,crossCheck=False): self[y].setVal(True) if crossCheck: + dpush('b_cc') self[y].row.checkNew(self.x) + dpop('b_cc') def newX(self,y,crossCheck=False): dprint('nx %s%s@%s'%('C',self.x,y)) self[y].setVal(False) if crossCheck: + dpush('x_cc') self[y].row.checkX(self.x,y) + dpop('x_cc') class Cell: def __init__(self,row,y,column,x): @@ -438,7 +452,11 @@ class Nono(dict): # 0,0 is upper left, so increasing y goes _downwards_, to match the standard layout def __init__(self,runsPerRow,runsPerCol): + global SOLVER self.loop=0 + self.dp='' + self.dstate=[] + SOLVER=self n=self.n=len(runsPerCol) if n!=len(runsPerRow): print("losing r:%s x c:%s"%(len(runsPerRow),n),sys.stderr) @@ -481,7 +499,16 @@ print(someChanged) print(self) +def dpush(s): + SOLVER.dp+=' ' + SOLVER.dstate.append(s) + +def dpop(s): + assert(SOLVER.dstate.pop()==s) + SOLVER.dp=SOLVER.dp[1:] + def dprint(*args): + print(SOLVER.dp,end='') print(*args) sys.stdout.flush()