changeset 56:40273cb7c7fc simple

begin trivial approach
author Henry Thompson <ht@markup.co.uk>
date Mon, 29 May 2023 23:14:59 +0100
parents 68004ce55703
children 057b52746850
files nono.py
diffstat 1 files changed, 24 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/nono.py	Mon May 29 22:24:53 2023 +0100
+++ b/nono.py	Mon May 29 23:14:59 2023 +0100
@@ -1,19 +1,8 @@
 #!/usr/bin/python3
-# Expects e.g. ^A copy from Nonograms dprint preview cols, then blank line, then rows
-#  rows are space-separated
-#  cols are one-digit-after-another, unless some 2-digit, in which case x is separator
-# E.g.
-# 13x1x2
-# 19
-# maps to
-# 13
-# 1  1
-# 2  9
 # New version, input taken from Nonograms Outer HTML plus
 #  > fgrep 'task = ' nono10.xhtml|tr ';' '\n' | fgrep task\ = | sed 's/^.*= //'| tr -d \'
 #  E.g. 8/5.1/2.3/2.1/4.3/3.4/2/1.1/3/5.2/2.2/2.2/1.3.2/5.1/3.1.1/2/2.3.1/7.1/1.1.2/3.2
 
-
 import sys
 
 Red=''
@@ -33,9 +22,10 @@
     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
     self.runs=self.origRuns=runs
+    self.rn=len(runs)
     self.initialComplete=[]
     self.finalComplete=[]
-    self.resetAllRuns()
+    #self.resetAllRuns()
 
   def __repr__(self):
     return "V@%s%s:%s"%(self.x,self.origRuns,list.__repr__(self))
@@ -386,6 +376,20 @@
     self.x=pos
     self.height=self.myPrintSize()
 
+#=============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
+
   def updateHeader(self,*,maxHeight=None,r=None,pre=None):
     dprint('CuH',r,pre)
     if maxHeight is None:
@@ -497,7 +501,15 @@
     lines+=[str(r) for r in self.rows]
     return "\n".join(lines)
 
+#=============new simple============
+  def pass0(self): # do columns of empty layout
+    for c in self.columns:
+      c.pass0()
+
   def solve(self):
+    self.pass0()
+    print(self)
+    return
     someChanged=1
     while someChanged>0:
       self.loop+=1