# HG changeset patch # User Henry Thompson # Date 1685642542 -3600 # Node ID a3aaf6c085f4b77cd02ad47f7ad3419b15b41219 # Parent 057b527468502e7aa32c88275f0a183191763be5 pass0, initial display working with Run and Space diff -r 057b52746850 -r a3aaf6c085f4 nono.py --- a/nono.py Thu Jun 01 18:21:56 2023 +0100 +++ b/nono.py Thu Jun 01 19:02:22 2023 +0100 @@ -19,6 +19,7 @@ self.n=n self.i=i self.j=j + self.s=j-i self.done=False def __str__(self): @@ -32,10 +33,11 @@ self.n=n self.i=i self.j=j + self.s=j-i self.done=False def __str__(self): - return '-' + return '' class Vector(list): # reads top-to-bottom or left-to-right @@ -73,7 +75,7 @@ return '%s|'%('|'.join(str(c) for c in self)) def myPrintSize(self): - return sum(len(str(run)) for run in self.runs) + return sum((len(str(run)) if isinstance(run,Run) else 1) for run in self.runs) #=========v-old-v============ @@ -365,19 +367,12 @@ self.marginN-=r+1 self.updateHeader(r=r,pre=False) -#=============new simple============ + #=============new simple============ def pass0(self): - need=sum(1+self.runs[k] for k in range(self.rn))-1 - space=self.n-need - p=0 - for run in self.runs: - if run>space: - for p in range(p+space,p+run): - self[p].setVal(True) - p+=1 - else: - p+=run - p+=1 + for i in range(0,len(self.runs),2): + run=self.runs[i] + for p in range(run.i+run.s,run.i+run.n): + self[p].setVal(True) class Row(Vector): cLet='R' @@ -389,7 +384,7 @@ self.width=self.myPrintSize() def __str__(self): - return ((self.fmt%(' '.join(str(r) for r in self.runs)))+ + return ((self.fmt%(' '.join(str(r) for r in self.runs if isinstance(r,Run))))+ Vector.__str__(self)) def updateHeader(self,*,maxWidth=None,r=None,pre=None): @@ -461,7 +456,7 @@ self.suffix=[] self.prespace=maxHeight - self.height # pad to same 'height' self.fmt="%s%%s"%(' '*self.prespace) - header=('-'.join(str(c) for c in self.runs)) + header=('-'.join(str(c) for c in self.runs if isinstance(c,Run))) self.header=self.fmt%header dprint(self.header) @@ -609,6 +604,5 @@ rows=[[int(i) for i in v.split('.')] for v in vv[n:]] solver=Nono(rows,cols) - breakpoint() solver.solve()