changeset 12:ede2551ae7d9

red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sun, 15 Mar 2020 19:08:44 +0000
parents 1b9daa849b0f
children 70993b538ddb
files nono.py
diffstat 1 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/nono.py	Sun Mar 15 17:05:49 2020 +0000
+++ b/nono.py	Sun Mar 15 19:08:44 2020 +0000
@@ -187,13 +187,15 @@
     # New blob at pos, can we complete anything?
     # Assuming @@ FTTB that it's never possible to definitively complete a
     #  non-marginal run, which is wrong if the length is unique and it's bounded...
+    start0=0 if self.margin0==0 else self.margin0+1
+    startN=self.marginN if (self.marginN==self.n-1) else self.marginN-1
     changed=False
     # First, find our boundaries:
     s=pos # start index of our run
-    while s>self.margin0 and self[s-1].val is True:
+    while s>start0 and self[s-1].val is True:
       s-=1
     f=pos # finish index of our run
-    while f<self.marginN and self[f+1].val is True:
+    while f<startN and self[f+1].val is True:
       f+=1
     l=(f-s)+1 # our length
     print('%s:%s,%s,%s,%s:<%s>'%(str(self.__class__.__name__)[0],s,f,l,self.runs,self))
@@ -204,14 +206,14 @@
       return
     if self.runs[0]==l:
       # is it safely left marginal, i.e. no blobs or big enough gaps before us?
-      if self.marginal(range(self.margin0,s),l):
+      if self.marginal(range(start0,s),l):
         changed=True
         dprint('n1')
         # mark our margins
-        for i in range(self.margin0+1,s):
+        for i in range(start0,s):
           if self[i].val is None:
             self[i].setVal(False)
-        if f<self.marginN-1:
+        if f<startN:
           if self[f+1].val is None:
             self[f+1].setVal(False)
         self.found0(f) # pull in the start margin at least to f+2
@@ -220,14 +222,14 @@
     if not changed:
       if self.runs[-1]==l:
         # is it safely _right_ marginal, i.e. no blobs or big enough gaps _after_ us?
-        if self.marginal(range(self.marginN-1,f,-1),l):
+        if self.marginal(range(startN,f,-1),l):
           changed=True
           dprint('n2')
           # mark our margins
-          for i in range(self.marginN-1,f,-1):
+          for i in range(startN,f,-1):
             if self[i].val is None:
               self[i].setVal(False)
-          if s>self.margin0+1:
+          if s>start0:
             if self[s-1].val is None:
               self[s-1].setVal(False)
           self.foundN(s) # pull in the finish margin at least to s-2
@@ -292,7 +294,7 @@
     if maxWidth is None:
       # update
       if pre:
-        self.infix+=(RedFmt%r)+" "
+        self.infix+=(RedFmt%r)+(" " if self.runs else "")
       else:
         # post
         self.suffix=" "+RedFmt%r+self.suffix
@@ -323,7 +325,7 @@
       if pre:
         for rc in str(r):
           self.infix.append(RedFmt%rc)
-        self.infix.append("-")
+        self.infix.append("-" if self.runs else "")
       else:
         # post
         ins=["-"]