changeset 58:a3aaf6c085f4 simple

pass0, initial display working with Run and Space
author Henry Thompson <ht@markup.co.uk>
date Thu, 01 Jun 2023 19:02:22 +0100
parents 057b52746850
children c22f83e049a9
files nono.py
diffstat 1 files changed, 11 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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()