changeset 74:0245bc07f16c simple

try to simplify Rows/Cols (do without?) by hiving off the run-counts copletely
author Henry Thompson <ht@markup.co.uk>
date Sat, 09 Aug 2025 15:59:19 -0400
parents 63e87db2bc31
children
files nono.py
diffstat 1 files changed, 21 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/nono.py	Sat Aug 09 15:56:58 2025 -0400
+++ b/nono.py	Sat Aug 09 15:59:19 2025 -0400
@@ -10,7 +10,7 @@
 # By cases, wrt types of change of a cell in its runs
 # Change at the margin:
 #  New fill: complete the run and discard it, kill the other end and queue it
-#      dead: advance margin and add fill to any internal sequences of fills (always?), queue the new fill(s)
+#      dead: advance margin and append a new fill to any internal sequences of fills (always?), queue the new fill(s)
 # Change in the middle
 #  New dead: If deterministic, split the run in two and requeue the cell (now in two runs)
 #      fill: If deterministic single gap at any end, kill, split, and requeue the cell (now in two runs)
@@ -18,6 +18,7 @@
 # Doesn't yet cover everything, e.g. killing gaps that are too small to be filled
 # Do we need to actually represent run-internal segments, e.g. skips and bars?
 
+# Hypothesis: we only need Columns and Rows for printing
 
 import sys
 
@@ -27,8 +28,7 @@
 
 
 class Run:
-  '''What we're looking for, converted eventually into what
-  we've found.
+  '''What we're looking for, converted eventually into what we've found.
   "left" and "right" make sense for Rows, for Columns read "above" and "below"'''
 
   def __init__(self, n, i, j):
@@ -73,9 +73,9 @@
 
 class Vector(list):
   # reads top-to-bottom or left-to-right
-  def __init__(self, n, m):
+  def __init__(self, m, left, right):
+    self.n = n = (left.x - right.x) + 1 # size
     list.__init__(self, list(range(n)))
-    self.n = n  # size
     self.m = m  # parent NoNo
     self.margin0 = 0  # a run can start here, so if >0 then self[m0-1].val must be False
     self.marginN = n - 1  # a run can end here, so if <n-1 then self[mN+1].val ditto
@@ -196,9 +196,9 @@
 class Row(Vector):
   cLet = "R"
 
-  def __init__(self, n, m, pos):
-    Vector.__init__(self, n, m)
-    self.y = pos
+  def __init__(self, m, left, right):
+    Vector.__init__(self, left, right, m)
+    self.y = left.y
 
   def __repr__(self):
     return "R@%s%s:%s" % (self.y, self.runs, list.__repr__(self))
@@ -233,9 +233,9 @@
 class Column(Vector):
   cLet = "C"
 
-  def __init__(self, n, m, pos):
-    Vector.__init__(self, n, m)
-    self.x = pos
+  def __init__(self, m, top, bottom):
+    Vector.__init__(self, top, bottom, m)
+    self.x = top.x
 
   def __repr__(self):
     return "C@%s%s:%s" % (self.x, self.runs, list.__repr__(self))
@@ -280,15 +280,10 @@
 
 
 class Cell:
-  def __init__(self, row, y, column, x):
-    # At the intersection of row and column Vectors
-    self.row = row
-    self.column = column
+  def __init__(self, x, y):
     self.x = x
     self.y = y
     self.val = None  # three valued: None(unknown), True(filled), False(empty)
-    self.row[x] = self
-    self.column[y] = self
 
   def __repr__(self):
     return "c@(%s,%s):%s" % (self.x, self.y, self.val)
@@ -326,25 +321,24 @@
     self.dp = ""  # old depth hack
     self.debug = debug
     self.dstate = []
+    self.pending = [] # newly filled/dead cells whose runs need to be checkedo
     SOLVER = self
     n = self.n = len(runsPerCol)
     if n != len(runsPerRow):
       print("losing r:%s x c:%s" % (len(runsPerRow), n), sys.stderr)
       exit(1)
+    list.__init__(self,list(list(list(range(n)) for _ in range(n))))
     self.rc = runsPerRow
     self.cc = runsPerCol
     # print col nums>9 vertically :-(
-    self.columns = cc = [Column(n, self, i) for i in range(n)]
-    self.rows = rr = [Row(n, self, i) for i in range(n)]
-    for x in range(n):
-      for y in range(n):
-        self[x, y] = Cell(rr[y], y, cc[x], x)
+    self.rows = [[(self[x,y] := Cell(x,y)) for y in range(n)] for x in range(n)]
     # Need cells in place for the following
-    for row, runs in zip(rr, runsPerRow):
-      row.initRuns(runs)
-    for col, runs in zip(cc, runsPerCol):
-      col.initRuns(runs)
-    self.maxCRheight = maxCRheight = max(col.height for col in cc)
+    maxCRheight = 0
+    for i in range(n):
+      self.initRuns([Cell[i,y] for y in range(n)], runsPerRow[i])
+      self.initRuns([Cell[x,i] for x in range(n)], runsPerCol[i])
+      maxCRheight = max(maxCRheight = max(col.height for col in cc)
+    self.maxCRheight = maxCRheight
     for c in cc:
       c.updateHeader(maxHeight=maxCRheight)
     maxRRwidth = max(row.width for row in rr)