annotate nono.py @ 37:6543fcbb8abd actOnZero

stop some/most cross-checks, but x out a 0-counted cell in step processing
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 25 Mar 2020 21:44:13 +0000
parents 6c9e371b0325
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 #!/usr/bin/python3
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2 # Expects e.g. ^A copy from Nonograms dprint preview cols, then blank line, then rows
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3 # rows are space-separated
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 # cols are one-digit-after-another, unless some 2-digit, in which case x is separator
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5 # E.g.
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 # 13x1x2
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7 # 19
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 # maps to
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 # 13
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 # 1 1
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 # 2 9
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13 import sys
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 Red=''
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 eRed=''
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
17 RedFmt=Red+'%s'+eRed
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19 def interleave(*args):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 for vals in zip(*args):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 yield from vals
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23 class Vector(list):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 # reads top-to-bottom or left-to-right
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 def __init__(self,n,m,runs):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 list.__init__(self,list(range(n)))
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 self.n=n
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
28 self.m=m
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
29 self.margin0=0 # a run can start here, so if >0 then self[m0-1].val must be False
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
30 self.marginN=n-1 # a run can end here, so if <n-1 then self[mN+1].val ditto
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
31 self.runs=self.origRuns=runs
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
32 self.initialComplete=[]
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
33 self.finalComplete=[]
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
34 self.resetAllRuns()
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
35
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
36 def __repr__(self):
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
37 return "V@%s%s:%s"%(self.x,self.origRuns,list.__repr__(self))
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
38
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
39 def __str__(self):
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
40 return '%s|'%('|'.join(str(c) for c in self))
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
41
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
42 def myPrintSize(self):
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
43 return sum(len(str(run)) for run in self.runs)+len(self.runs)-1
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
44
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
45 def resetAllRuns(self):
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
46 # compute the set of all possible layouts for runs
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
47 self.rn=len(self.runs)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 rtot=sum(self.runs)
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
49 self.allRuns=list(self.seedList(0,0,self.margin0,self.marginN+1,
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
50 sum(1+self.runs[k] for k in range(self.rn))-1))
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
51 self.nar=len(self.allRuns)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
52
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
53 def seedList(self,i,j,pos0,posN,runLen):
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
54 """
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
55 :param i: starting skip before next run
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
56 :type i: 0 if pos==0 else 1
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
57 :param j: next run number
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
58 :type j: int
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
59 :param pos0: left margin
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
60 :type pos0: int
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
61 :param posN: right margin
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
62 :type posN: int
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
63 """
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
64 bound=posN-(pos0+runLen)+1
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
65 dprint('s',i,j,pos0,posN,runLen,bound)
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
66 if j==self.rn:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
67 yield []
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
68 return
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
69 r=self.runs[j]
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
70 for v in range(i,bound):
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
71 for sub in self.seedList(1,j+1,pos0+v+r,posN,runLen-(r+1)):
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
72 yield [-v,r]+sub
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
73
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
74 def step(self,pos):
37
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
75 changed=0
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
76 if self.runs==[]:
37
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
77 for i in range(self.n):
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
78 if self[i].val is None:
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
79 changed+=1
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
80 self.newX(i)
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
81 return changed
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
82 scratch=[0 if c.val is None else c.val for c in self]
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
83 wins=0
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
84 for k,runs in enumerate(self.allRuns):
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
85 dprint('=====pass %s.%s.%s.%s======'%(self.m.loop,self.cLet,pos,k))
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
86 if self.onepass(self.margin0,self.marginN+1,scratch,runs.copy()):
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
87 wins+=1
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
88 dprint(wins, scratch)
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
89 maybeSeq=None
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
90 inSeq=None
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
91 j=None
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
92 for i in range(self.n):
37
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
93 if scratch[i]==0:
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
94 # Never blobbed, if not x already x it
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
95 if self[i].val is None:
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
96 self.newX(i)
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
97 if scratch[i]>=wins:
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
98 # If blobby in _every_ pass, then must be a blob
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
99 if inSeq is None:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
100 inSeq=i if maybeSeq is None else maybeSeq
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
101 dprint('s1',inSeq)
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
102 maybeSeq=None
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
103 if self[i].val is None:
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
104 dprint('s1a',i)
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
105 self.newBlob(i,True) # Check cross-vector
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
106 j=i
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
107 changed=1
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
108 elif self[i].val is True:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
109 pass
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
110 else:
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
111 eprint("Shouldn't happen: attempt to blob where x already present! %s at %s"%(self,i),err=101)
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
112 elif inSeq is not None:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
113 if self[i].val is not True:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
114 inSeq=None
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
115 maybeSeq=None
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
116 dprint('s2',i-1,j)
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
117 if j is not None:
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
118 # Only if we actually added a blob at some point
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
119 dpush('b_s2')
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
120 self.checkNew(i-1)
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
121 dpop('b_s2')
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
122 elif self[i].val is True and maybeSeq is None:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
123 dprint('s3',i)
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
124 maybeSeq=i
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
125 dprint('s4',inSeq,i)
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
126 if inSeq is not None:
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
127 dpush('b_s4')
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
128 self.checkNew(i)
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
129 dpop('b_s4')
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
130 return changed
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
131
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
132 def onepass(self,i0,iBound,scratch,stack):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
133 """note that stack is not a simple run, but one with _negative_ numbers between
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
134 and possibly before the positive ones, indicating obligatory skips
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
135 """
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
136 i=i0 # starting index into self/scratch/maybe
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
137 maybe=[0]*self.n
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
138 dprint('r: %s'%stack,i0,iBound)
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
139 req=sum((-r if r<0 else r) for r in stack)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
140 while stack and i<iBound:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
141 r=rr=stack.pop(0)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
142 dprint('pop:',r)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
143 if r<1:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
144 # obligatory skip
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
145 # (Above init of self.allRuns is easier if we allow a 0 to be ignored
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
146 for k in range(i,i-r):
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
147 if self[k] is True:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
148 # has to be False or None to skip
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
149 dprint('x0',k)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
150 return False
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
151 i-=r
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
152 req+=r
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
153 r=rr=stack.pop(0)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
154 # rr is run remaining -- how many we still need
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
155 # First, check if we can start here: 0 is OK, and n>0 iff n-1 is None or False
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
156 # if i>0 and self[i-1].val is True:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
157 # dprint('x1',i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
158 # return
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
159 if (iBound-i)<req:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
160 # Can't win, give up altogether
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
161 dprint('x2',i,iBound,req)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
162 return False
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
163 j=i # start of run, if we find it
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
164 gapsFilled=0
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
165 dprint('top:',j)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
166 while rr>0:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
167 # guaranteed by check above that we won't run over the far end
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
168 c=self[i].val
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
169 if c is False:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
170 dprint('x3',i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
171 return False
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
172 if c is None:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
173 # we could add a blob here
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
174 gapsFilled+=1
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
175 # and a blob already present is OK
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
176 rr-=1
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
177 i+=1
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
178 # Maybe a win?
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
179 # look ahead, can we stop here?
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
180 if i<self.n and self[i].val is True:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
181 dprint('x4',i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
182 return False
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
183 # elif gapsFilled==0:
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
184 # # We must have crossed at least one gap...
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
185 # print("Shouldn't happen: no gap! me:%s i:%s j:%s rr:%s"%(self,i, j, rr),file=sys.stderr)
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
186 # raise Exception
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
187 # Victory!
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
188 dprint('c6',r,j,i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
189 for k in range(j,i):
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
190 maybe[k]+=1
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
191 req-=r
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
192 # on to the next run
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
193 # end of inner loop, did we win?
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
194 if (not stack) or i==iBound:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
195 # yes
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
196 dprint('win:',maybe)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
197 for k in range(iBound):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
198 scratch[k]+=maybe[k]
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
199 return True
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
200 eprint("Shouldn't happen? - fell through",stack,i,iBound,err=102)
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
201
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
202 def checkX(self,pos,crosspos):
37
6543fcbb8abd stop some/most cross-checks, but x out a 0-counted cell in step processing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 17
diff changeset
203 return
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
204 # New x at pos, are there others that can be xed out now?
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
205 # Overkill as is?
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
206 dprint('cx',self.cLet+str(crosspos),pos)
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
207 if self.runs:
15
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
208 start0=self.margin0 # 0 if self.margin0==0 else self.margin0+1
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
209 if self.marginal(range(start0,pos),self.runs[0]):
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
210 dprint('cx1a')
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
211 else:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
212 dprint('cx1b')
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
213 # if len(self.runs)>1:
15
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
214 startN=self.marginN # self.marginN if (self.marginN==self.n-1) else self.marginN-1
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
215 if self.marginal(range(startN,pos,-1),self.runs[-1]):
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
216 dprint('cx2a')
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
217 else:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
218 dprint('cx2b')
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
219
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
220 def checkNew(self,pos):
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
221 # New blob at pos, can we complete anything?
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
222 # Assuming @@ FTTB that it's never possible to definitively complete a
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
223 # non-marginal run, which is wrong if the length is unique and it's bounded...
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
224 start0=self.margin0 #0 if self.margin0==0 else self.margin0+1
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
225 startN=self.marginN # self.marginN if (self.marginN==self.n-1) else self.marginN-1
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
226 dprint('cn',start0,pos,startN)
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
227 changed=False
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
228 # First, find our boundaries:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
229 s=pos # start index of our run
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
230 if s>start0:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
231 while s>start0 and self[s-1].val is True:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
232 s-=1
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
233 f=pos # finish index of our run
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
234 if f<startN:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
235 while f<startN and self[f+1].val is True:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
236 f+=1
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
237 l=(f-s)+1 # our length
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
238 dprint('%s:%s,%s,%s,%s:<%s>'%(self.cLet,s,f,l,self.runs,self))
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
239 c=self.runs.count(l)
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
240 if c==0:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
241 # not big enough yet
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
242 dprint('x0')
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
243 return
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
244 if self.runs[0]==l:
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
245 # is it safely left marginal, i.e. no blobs or big enough gaps before us?
12
ede2551ae7d9 red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 11
diff changeset
246 if self.marginal(range(start0,s),l):
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
247 changed=True
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
248 dprint('n1')
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
249 # mark our margins
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
250 for i in range(start0,s): # not sure this is still needed since
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
251 # added gap-filling in self.marginal
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
252 if self[i].val is None:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
253 self.newX(i,False)
12
ede2551ae7d9 red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 11
diff changeset
254 if f<startN:
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
255 if self[f+1].val is None:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
256 self.newX(f+1,True)
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
257 self.found0(f) # pull in the start margin at least to f+2
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
258 else:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
259 dprint('x1a')
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
260 if not changed:
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
261 if self.runs[-1]==l:
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
262 # is it safely _right_ marginal, i.e. no blobs or big enough gaps _after_ us?
12
ede2551ae7d9 red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 11
diff changeset
263 if self.marginal(range(startN,f,-1),l):
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
264 changed=True
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
265 dprint('n2')
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
266 # mark our margins: still needed? see above
12
ede2551ae7d9 red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 11
diff changeset
267 for i in range(startN,f,-1):
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
268 if self[i].val is None:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
269 self.newX(i,False)
12
ede2551ae7d9 red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 11
diff changeset
270 if s>start0:
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
271 if self[s-1].val is None:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
272 self.newX(s-1,True)
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
273 self.foundN(s) # pull in the finish margin at least to s-2
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
274 else:
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
275 dprint('x2a')
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
276 else:
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
277 dprint('x2b')
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
278 if changed:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
279 self.resetAllRuns()
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
280
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
281 def marginal(self,rng,l):
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
282 dprint('m%s'%self.cLet,rng.start,rng.stop,rng.step,l)
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
283 g=0 # length of a gap
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
284 for i in rng:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
285 if self[i].val is True:
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
286 # Shouldn't be possible?
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
287 dprint('mx0')
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
288 return False
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
289 if self[i].val is False:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
290 if g>0:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
291 # Block a too-small gap
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
292 dprint('m1',i-g,i)
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
293 for j in range(i-g,i):
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
294 self.newX(j,True)
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
295 g=0
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
296 else:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
297 # None
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
298 g+=1
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
299 if g==l:
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
300 # run could fit here, so no go
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
301 dprint('mx1')
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
302 return False
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
303 if g>0:
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
304 # Block a too-small gap
17
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
305 if rng.step==1:
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
306 # forward
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
307 dprint('m2f',i-g,i)
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
308 for j in range(i+1-g,i+1):
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
309 self.newX(j,True)
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
310 else:
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
311 # backward
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
312 dprint('m2b',i+g,i)
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
313 for j in range(i+g-1,i-1,-1):
6c9e371b0325 doesn't break, what's there is good, but stuck part-way in 10a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 16
diff changeset
314 self.newX(j,True)
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
315 return True
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
316
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
317 def found0(self,i):
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
318 dprint('found0 called on %s at %s'%(self,i))
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
319 i=self.margin0
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
320 while self[i].val is False:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
321 i+=1
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
322 if self[i].val is True:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
323 r=self.runs.pop(0)
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
324 self.initialComplete.append(r)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
325 self.margin0+=r+1
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
326 self.updateHeader(r=r,pre=True)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
327
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
328 def foundN(self,i):
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
329 dprint('foundN called on %s at %s'%(self,i))
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
330 i=self.marginN
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
331 while self[i].val is False:
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
332 i-=1
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
333 if self[i].val is True:
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
334 r=self.runs.pop()
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
335 self.finalComplete=[r]+self.finalComplete
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
336 self.marginN-=r+1
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
337 self.updateHeader(r=r,pre=False)
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
338
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
339
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
340 class Row(Vector):
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
341 cLet='R'
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
342 def __init__(self,n,m,runs,pos):
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
343 Vector.__init__(self,n,m,runs)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
344 self.y=pos
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
345 self.width=self.myPrintSize()
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
346
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
347 def __str__(self):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
348 return ((self.fmt%(' '.join(str(r) for r in self.runs)))+
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
349 Vector.__str__(self))
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
350
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
351 def updateHeader(self,*,maxWidth=None,r=None,pre=None):
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
352 if maxWidth is None:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
353 # update
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
354 spacer=(" " if self.runs else "")
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
355 if pre:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
356 self.infix+=(RedFmt%r)+spacer
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
357 else:
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
358 # post
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
359 self.suffix=spacer+RedFmt%r+self.suffix
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
360 self.fmt="%s%s%%s%s|"%(self.prespace,self.infix,self.suffix)
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
361 else:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
362 # init
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
363 self.maxWidth=maxWidth
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
364 self.prespace=' '*(maxWidth-self.width)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
365 self.fmt="%s%%s|"%self.prespace
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
366 self.infix=""
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
367 self.suffix=""
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
368
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
369 def newBlob(self,x,crossCheck=False):
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
370 self[x].setVal(True)
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
371 if crossCheck:
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
372 dpush('b_cc')
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
373 self[x].column.checkNew(self.y)
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
374 dpop('b_cc')
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
375
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
376 def newX(self,x,crossCheck=False):
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
377 dprint('nx %s%s@%s'%('R',self.y,x))
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
378 self[x].setVal(False)
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
379 if crossCheck:
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
380 dpush('x_cc')
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
381 self[x].column.checkX(self.y,x)
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
382 dpop('x_cc')
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
383
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
384 class Column(Vector):
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
385 cLet='C'
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
386 def __init__(self,n,m,runs,pos):
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
387 Vector.__init__(self,n,m,runs)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
388 self.x=pos
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
389 self.height=self.myPrintSize()
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
390
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
391 def updateHeader(self,*,maxHeight=None,r=None,pre=None):
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
392 dprint('CuH',r,pre)
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
393 if maxHeight is None:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
394 # update
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
395 if pre:
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
396 for rc in str(r):
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
397 self.infix.append(RedFmt%rc)
15
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
398 if self.runs:
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
399 self.infix.append('-')
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
400 else:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
401 # post
15
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
402 ins=["-"] if self.runs else []
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
403 for rc in str(r):
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
404 ins.append(RedFmt%r)
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
405 self.suffix=ins+self.suffix
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
406 dprint('CuH1: |%s|,%s,%s,%s'%(self.prespace,self.infix,self.suffix,self.runs))
15
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
407 self.header=([" "]*self.prespace)+\
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
408 self.infix+\
15
22b0894c0f4c fixed Column.updateHeader wrt 5a, but broke it wrt C0 and missing red for R2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 14
diff changeset
409 (['-'.join(str(c) for c in self.runs)] if self.runs else [])+\
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
410 self.suffix
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
411 else:
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
412 # init
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
413 self.maxHeight=maxHeight
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
414 self.infix=[]
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
415 self.suffix=[]
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
416 self.prespace=maxHeight - self.height # pad to same 'height'
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
417 self.fmt="%s%%s"%(' '*self.prespace)
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
418 header=('-'.join(str(c) for c in self.runs))
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
419 self.header=self.fmt%header
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
420 dprint(self.header)
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
421
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
422 def newBlob(self,y,crossCheck=False):
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
423 self[y].setVal(True)
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
424 if crossCheck:
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
425 dpush('b_cc')
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
426 self[y].row.checkNew(self.x)
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
427 dpop('b_cc')
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
428
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
429 def newX(self,y,crossCheck=False):
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
430 dprint('nx %s%s@%s'%('C',self.x,y))
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
431 self[y].setVal(False)
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
432 if crossCheck:
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
433 dpush('x_cc')
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
434 self[y].row.checkX(self.x,y)
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
435 dpop('x_cc')
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
436
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
437 class Cell:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
438 def __init__(self,row,y,column,x):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
439 # At the intersection of row and column Vectors
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
440 self.row=row
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
441 self.column=column
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
442 self.x=x
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
443 self.y=y
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
444 self.val=None # three valued: None(unknown), True(filled), False(empty)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
445 self.row[x]=self
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
446 self.column[y]=self
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
447
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
448 def __repr__(self):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
449 return "C@(%s,%s):%s"%(self.x,self.y,self.val)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
450
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
451 def __str__(self):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
452 return ' ' if self.val is None else ('\u25A0' if self.val else 'x')
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
453
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
454 def setVal(self,v):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
455 if v is True:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
456 if self.val is False:
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
457 wprint("Warning: x -> * at %s,%s"%(self.x,self.y))
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
458 elif self.val is True:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
459 # No-op
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
460 return
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
461 self.val=v
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
462 else:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
463 if self.val is not None:
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
464 wprint("Warning: %s -> %s at %s,%s"%(self.val,v,self.x,self.y))
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
465 self.val=v
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
466
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
467
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
468 class Nono(dict):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
469 # 0,0 is upper left, so increasing y goes _downwards_, to match the standard layout
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
470 def __init__(self,runsPerRow,runsPerCol):
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
471 global SOLVER
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
472 self.loop=0
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
473 self.dp=''
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
474 self.dstate=[]
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
475 SOLVER=self
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
476 n=self.n=len(runsPerCol)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
477 if n!=len(runsPerRow):
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
478 print("losing r:%s x c:%s"%(len(runsPerRow),n),sys.stderr)
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
479 exit(1)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
480 self.rc=runsPerRow
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
481 self.cc=runsPerCol
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
482 # print col nums>9 vertically :-(
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
483 self.columns=cc=[Column(n,self,runsPerCol[i],i) for i in range(n)]
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
484 self.maxCRheight=maxCRheight=max(col.height for col in cc)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
485 for c in cc:
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
486 c.updateHeader(maxHeight=maxCRheight)
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
487 self.rows=rr=[Row(n,self,runsPerRow[i],i) for i in range(n)]
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
488 maxRRwidth=max(row.width for row in rr)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
489 for r in rr:
10
0a24625b33fa checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 9
diff changeset
490 r.updateHeader(maxWidth=maxRRwidth)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
491 self.rowfmt="%s|%%s|"%(' '*maxRRwidth)
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
492 for x in range(n):
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
493 for y in range(n):
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
494 self[(x,y)]=Cell(rr[y],y,cc[x],x)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
495
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
496 def __str__(self):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
497 lines=[self.rowfmt%('|'.join([(self.columns[i]).header[j] for i in range(self.n)])) # 'rotate'
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
498 for j in range(self.maxCRheight)]
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
499 lines+=[str(r) for r in self.rows]
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
500 return "\n".join(lines)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
501
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
502 def solve(self):
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
503 someChanged=1
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
504 while someChanged>0:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
505 self.loop+=1
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
506 someChanged=0
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
507 dprint("***Solve C %s***"%self.loop)
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
508 for c in self.columns:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
509 someChanged+=c.step(c.x)
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
510 print(someChanged)
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
511 print(self)
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
512 dprint("***Solve R %s***"%self.loop)
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
513 for r in self.rows:
13
70993b538ddb works on 5a
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
514 someChanged+=r.step(r.y)
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
515 print(someChanged)
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
516 print(self)
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
517
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
518 def dpush(s):
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
519 SOLVER.dp+=' '
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
520 SOLVER.dstate.append(s)
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
521
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
522 def dpop(s):
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
523 assert(SOLVER.dstate.pop()==s)
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
524 SOLVER.dp=SOLVER.dp[1:]
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
525
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
526 def dprint(*args):
16
a7a10e40b344 5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 15
diff changeset
527 print(SOLVER.dp,end='')
14
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
528 print(*args)
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
529 sys.stdout.flush()
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
530
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
531 def eprint(*args,**kw):
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
532 print(*args,file=sys.stderr)
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
533 sys.stderr.flush()
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
534 exit(kw['err'])
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
535
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
536 def wprint(*args):
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
537 print(*args,file=sys.stderr)
1e961cf10f88 10a is losing at 1R
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 13
diff changeset
538 sys.stderr.flush()
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
539
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
540 if __name__ == '__main__':
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
541 if len(sys.argv)>1:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
542 f=open(sys.argv[1])
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
543 else:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
544 f=sys.stdin
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
545
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
546 cols=[]
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
547
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
548 for l in f:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
549 l=l.rstrip()
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
550 if l=='':
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
551 break
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
552 if 'x' in l:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
553 vv=[int(s) for s in l.split('x')]
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
554 else:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
555 vv=[int(c) for c in l]
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
556 cols.append(vv)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
557
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
558 rows=[[int(s) for s in l.split()] for l in f]
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
559
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
560 solver=Nono(rows,cols)
11
1b9daa849b0f A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 10
diff changeset
561 solver.solve()