Mercurial > hg > python
annotate nono.py @ 59:c22f83e049a9 simple
check0 works for nono10,
but is broken in that col 3 w/o the row 7 hit would find the row 3 hit
as satisfying the last (2nd) run, which isn't _necessarily_ correct
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Sat, 03 Jun 2023 22:11:12 +0100 |
parents | a3aaf6c085f4 |
children |
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 |
55
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
2 # New version, input taken from Nonograms Outer HTML plus |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
3 # > fgrep 'task = ' nono10.xhtml|tr ';' '\n' | fgrep task\ = | sed 's/^.*= //'| tr -d \' |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
4 # 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 |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
5 |
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
|
6 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
|
7 |
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 Red='[31m' |
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 eRed='[39m' |
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
|
10 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
|
11 |
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 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
|
13 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
|
14 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
|
15 |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
16 class Run: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
17 def __init__(self,n,i,j): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
18 # A run of length n, starting within [i,j] |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
19 self.n=n |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
20 self.i=i |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
21 self.j=j |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
22 self.s=j-i |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
23 self.done=False |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
24 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
25 def __str__(self): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
26 return str(self.n) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
27 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
28 class Space: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
29 def __init__(self,n,i,j): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
30 # A space of length 1..n, starting within [i,j] |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
31 # Once done, length == n |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
32 assert n>0 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
33 self.n=n |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
34 self.i=i |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
35 self.j=j |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
36 self.s=j-i |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
37 self.done=False |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
38 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
39 def __str__(self): |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
40 return '' |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
41 |
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
|
42 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
|
43 # reads top-to-bottom or left-to-right |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
44 def __init__(self,n,m): |
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
|
45 list.__init__(self,list(range(n))) |
55
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
46 self.n=n # size |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
47 self.m=m # parent NoNo |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
48 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
|
49 self.marginN=n-1 # a run can end here, so if <n-1 then self[mN+1].val ditto |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
50 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
51 def initRuns(self,runs): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
52 # Set runs to alternating list of Run and Skip |
56 | 53 self.rn=len(runs) |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
54 self.runs=[] |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
55 if self.rn==0: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
56 # No runs means a vector of x |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
57 for c in self: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
58 c.setVal(False) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
59 else: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
60 need=sum(1+runs[k] for k in range(self.rn))-1 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
61 space=self.n-need |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
62 pos=0 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
63 while runs: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
64 self.runs.append(Run(r:=runs.pop(0),pos,pos+space)) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
65 pos+=r |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
66 if runs: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
67 self.runs.append(Space(space,pos,pos+space)) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
68 pos+=1 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
69 self.initDisp() |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
70 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
71 def __str__(self): |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
72 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
|
73 |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
74 def myPrintSize(self): |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
75 return sum((len(str(run)) if isinstance(run,Run) else 1) for run in self.runs) |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
76 |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
77 #=========v-old-v============ |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
78 |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
79 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
|
80 # 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 |
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
|
87 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
|
88 """ |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
89 :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
|
90 :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
|
91 :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
|
92 :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
|
93 :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
|
94 :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
|
95 :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
|
96 :type posN: int |
55
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
97 :return: list of runlens separated, possibly prefixed, with skips as negative integers |
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 """ |
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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 |
13 | 109 def step(self,pos): |
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
|
110 if self.runs==[]: |
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
|
111 return 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
|
112 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
|
113 wins=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
|
114 changed=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
|
115 for k,runs in enumerate(self.allRuns): |
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
|
116 if (self.m.loop,self.cLet,pos,k)==(1,'R',7,5): |
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
|
117 print(self.m) |
13 | 118 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
|
119 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
|
120 wins+=1 |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
121 dprint(wins, scratch) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
122 maybeSeq=None |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
123 inSeq=None |
14 | 124 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
|
125 for i in range(self.n): |
13 | 126 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
|
127 # 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
|
128 if inSeq is None: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
129 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
|
130 dprint('s1',inSeq) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
131 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
|
132 if self[i].val is None: |
14 | 133 dprint('s1a',i) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
134 self.newBlob(i,True) # Check cross-vector |
14 | 135 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
|
136 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
|
137 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
|
138 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
|
139 else: |
14 | 140 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
|
141 elif inSeq is not None: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
142 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
|
143 inSeq=None |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
144 maybeSeq=None |
14 | 145 dprint('s2',i-1,j) |
146 if j is not None: | |
147 # 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
|
148 dpush('b_s2') |
14 | 149 self.checkNew(i-1) |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
150 dpop('b_s2') |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
151 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
|
152 dprint('s3',i) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
153 maybeSeq=i |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
154 dprint('s4',inSeq,i) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
155 if inSeq is not None: |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
156 dpush('b_s4') |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
157 self.checkNew(i) |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
158 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
|
159 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
|
160 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
161 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
|
162 """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
|
163 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
|
164 """ |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 # 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
|
174 # (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
|
175 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
|
176 if self[k] is True: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
177 # 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
|
178 dprint('x0',k) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 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
|
183 # 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
|
184 # 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
|
185 # 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
|
186 # dprint('x1',i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
187 # 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
|
188 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
|
189 # 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
|
190 dprint('x2',i,iBound,req) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
191 return False |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
192 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
|
193 gapsFilled=0 |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
194 dprint('top:',j) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
195 while rr>0: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
196 # 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
|
197 c=self[i].val |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
198 if c is False: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
199 dprint('x3',i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
200 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
|
201 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
|
202 # 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
|
203 gapsFilled+=1 |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
204 # 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
|
205 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
|
206 i+=1 |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
207 # Maybe a win? |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
208 # 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
|
209 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
|
210 dprint('x4',i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
211 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
|
212 # 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
|
213 # # 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
|
214 # 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
|
215 # raise Exception |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
216 # Victory! |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
217 dprint('c6',r,j,i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
218 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
|
219 maybe[k]+=1 |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
220 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
|
221 # 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
|
222 # 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
|
223 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
|
224 # 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
|
225 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
|
226 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
|
227 scratch[k]+=maybe[k] |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
228 return True |
14 | 229 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
|
230 |
13 | 231 def checkX(self,pos,crosspos): |
232 # New x at pos, are there others that can be xed out now? | |
233 # Overkill as is? | |
234 dprint('cx',self.cLet+str(crosspos),pos) | |
235 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
|
236 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
|
237 if self.marginal(range(start0,pos),self.runs[0]): |
13 | 238 dprint('cx1a') |
239 else: | |
240 dprint('cx1b') | |
241 # 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
|
242 startN=self.marginN # self.marginN if (self.marginN==self.n-1) else self.marginN-1 |
13 | 243 if self.marginal(range(startN,pos,-1),self.runs[-1]): |
244 dprint('cx2a') | |
245 else: | |
246 dprint('cx2b') | |
247 | |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
248 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
|
249 # 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
|
250 # 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
|
251 # non-marginal run, which is wrong if the length is unique and it's bounded... |
13 | 252 start0=self.margin0 #0 if self.margin0==0 else self.margin0+1 |
253 startN=self.marginN # self.marginN if (self.marginN==self.n-1) else self.marginN-1 | |
254 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
|
255 changed=False |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
256 # 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
|
257 s=pos # start index of our run |
13 | 258 if s>start0: |
259 while s>start0 and self[s-1].val is True: | |
260 s-=1 | |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
261 f=pos # finish index of our run |
13 | 262 if f<startN: |
263 while f<startN and self[f+1].val is True: | |
264 f+=1 | |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
265 l=(f-s)+1 # our length |
13 | 266 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
|
267 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
|
268 if c==0: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
269 # not big enough yet |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
270 dprint('x0') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
271 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
|
272 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
|
273 # 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
|
274 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
|
275 changed=True |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
276 dprint('n1') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
277 # mark our margins |
13 | 278 for i in range(start0,s): # not sure this is still needed since |
279 # 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
|
280 if self[i].val is None: |
13 | 281 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
|
282 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
|
283 if self[f+1].val is None: |
13 | 284 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
|
285 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
|
286 else: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 # 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
|
291 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
|
292 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
|
293 dprint('n2') |
13 | 294 # 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
|
295 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
|
296 if self[i].val is None: |
13 | 297 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
|
298 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
|
299 if self[s-1].val is None: |
13 | 300 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
|
301 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
|
302 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
|
303 dprint('x2a') |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
304 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
|
305 dprint('x2b') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
306 if changed: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
307 self.resetAllRuns() |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
308 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
309 def marginal(self,rng,l): |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
310 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
|
311 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
|
312 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
|
313 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
|
314 # Shouldn't be possible? |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
315 dprint('mx0') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
316 return False |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
317 if self[i].val is False: |
13 | 318 if g>0: |
319 # Block a too-small gap | |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
320 dprint('m1',i-g,i) |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
321 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
|
322 self.newX(j,True) |
13 | 323 g=0 |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
324 else: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
325 # None |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
326 g+=1 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
327 if g==l: |
14 | 328 # 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
|
329 dprint('mx1') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
330 return False |
13 | 331 if g>0: |
332 # 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
|
333 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
|
334 # 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 # 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
|
340 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
|
341 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
|
342 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
|
343 return True |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
344 |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
345 def found0(self,i): |
13 | 346 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
|
347 i=self.margin0 |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
348 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
|
349 i+=1 |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
350 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
|
351 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
|
352 self.initialComplete.append(r) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
353 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
|
354 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
|
355 |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
356 def foundN(self,i): |
13 | 357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
367 #=============new simple============ |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
368 def pass0(self): |
59 | 369 # simple first pass down/across a row |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
370 for i in range(0,len(self.runs),2): |
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
371 run=self.runs[i] |
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
372 for p in range(run.i+run.s,run.i+run.n): |
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
373 self[p].setVal(True) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
374 |
59 | 375 def check0(self): |
376 # check 1st and last not-done runs for completeness | |
377 # forwards | |
378 for i in range(0,len(self.runs),2): | |
379 run=self.runs[i] | |
380 if not run.done: | |
381 # look for first True cell | |
382 for p in range(run.i,run.i+run.s+1): | |
383 if self[p].val: | |
384 l=self.trueRun(p,run.n) | |
385 if l==run.n: | |
386 if p!=0: | |
387 self[p-1].setVal(False) | |
388 e=p+l | |
389 if e!=self.n: | |
390 self[e].setVal(False) | |
391 break | |
392 break | |
393 # and backwards | |
394 m=len(self.runs)-1 | |
395 # if isinstance(self,Column) and self.x==3: | |
396 # breakpoint() | |
397 for i in range(0,m+1,2): | |
398 run=self.runs[m-i] | |
399 if not run.done: | |
400 # look for first True cell | |
401 for p in range(run.i+run.s,run.i-1,-1): | |
402 if self[p].val: | |
403 l=self.trueRun(p,run.n,-1) | |
404 if l==run.n: | |
405 e=p-l | |
406 if e!=0: | |
407 self[e].setVal(False) | |
408 if p+1!=self.n: | |
409 self[p+1].setVal(False) | |
410 break | |
411 break | |
412 | |
413 def trueRun(self,p,n,delta=1): | |
414 res=0 | |
415 for i in range(p,p+(delta*n),delta): | |
416 if self[i].val: | |
417 res+=1 | |
418 else: | |
419 break | |
420 return res | |
421 | |
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
|
422 class Row(Vector): |
13 | 423 cLet='R' |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
424 def __init__(self,n,m,pos): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
425 Vector.__init__(self,n,m) |
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
|
426 self.y=pos |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
427 |
59 | 428 def __repr__(self): |
429 return "R@%s%s:%s"%(self.y,self.runs,list.__repr__(self)) | |
430 | |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
431 def initDisp(self): |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
432 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
|
433 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
434 def __str__(self): |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
435 return ((self.fmt%(' '.join(str(r) for r in self.runs if isinstance(r,Run))))+ |
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
|
436 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
|
437 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
438 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
|
439 if maxWidth is None: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
440 # update |
13 | 441 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
|
442 if pre: |
13 | 443 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
|
444 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
|
445 # post |
13 | 446 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
|
447 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
|
448 else: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
449 # init |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
450 self.maxWidth=maxWidth |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
451 self.prespace=' '*(maxWidth-self.width) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
452 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
|
453 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
|
454 self.suffix="" |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
455 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
456 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
|
457 self[x].setVal(True) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
458 if crossCheck: |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
459 dpush('b_cc') |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
460 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
|
461 dpop('b_cc') |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
462 |
13 | 463 def newX(self,x,crossCheck=False): |
464 dprint('nx %s%s@%s'%('R',self.y,x)) | |
465 self[x].setVal(False) | |
466 if crossCheck: | |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
467 dpush('x_cc') |
13 | 468 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
|
469 dpop('x_cc') |
13 | 470 |
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
|
471 class Column(Vector): |
13 | 472 cLet='C' |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
473 def __init__(self,n,m,pos): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
474 Vector.__init__(self,n,m) |
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
|
475 self.x=pos |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
476 |
59 | 477 def __repr__(self): |
478 return "C@%s%s:%s"%(self.x,self.runs,list.__repr__(self)) | |
479 | |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
480 def initDisp(self): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
481 self.height=self.myPrintSize() |
56 | 482 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
483 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
|
484 dprint('CuH',r,pre) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
485 if maxHeight is None: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
486 # update |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 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
|
491 self.infix.append('-') |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
492 else: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
493 # 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 (['-'.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
|
502 self.suffix |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
503 else: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
504 # init |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
505 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
|
506 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
|
507 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
|
508 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
|
509 self.fmt="%s%%s"%(' '*self.prespace) |
58
a3aaf6c085f4
pass0, initial display working with Run and Space
Henry Thompson <ht@markup.co.uk>
parents:
57
diff
changeset
|
510 header=('-'.join(str(c) for c in self.runs if isinstance(c,Run))) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
511 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
|
512 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
|
513 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
514 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
|
515 self[y].setVal(True) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
516 if crossCheck: |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
517 dpush('b_cc') |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
518 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
|
519 dpop('b_cc') |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
520 |
13 | 521 def newX(self,y,crossCheck=False): |
522 dprint('nx %s%s@%s'%('C',self.x,y)) | |
523 self[y].setVal(False) | |
524 if crossCheck: | |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
525 dpush('x_cc') |
13 | 526 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
|
527 dpop('x_cc') |
13 | 528 |
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
|
529 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
|
530 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
|
531 # 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
|
532 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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
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 def __repr__(self): |
59 | 541 return "c@(%s,%s):%s"%(self.x,self.y,self.val) |
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
|
542 |
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 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
|
544 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
|
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 def setVal(self,v): |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
547 # Returns true iff old value was None |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
548 assert v in (True, False) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
549 if v == self.val: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
550 return False |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
551 if self.val is not None: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
552 eprint("Reset not allowed: %s -> %s at %s,%s"%(self.val, v, self.x,self.y),err=103) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
553 self.val=v |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
554 return True |
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
|
555 |
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 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
|
557 # 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
|
558 def __init__(self,runsPerRow,runsPerCol): |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
559 global SOLVER |
13 | 560 self.loop=0 |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
561 self.dp='' |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
562 self.dstate=[] |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
563 SOLVER=self |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
564 n=self.n=len(runsPerCol) |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
565 if n!=len(runsPerRow): |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
566 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
|
567 exit(1) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
568 self.rc=runsPerRow |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
569 self.cc=runsPerCol |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
570 # print col nums>9 vertically :-( |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
571 self.columns=cc=[Column(n,self,i) for i in range(n)] |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
572 self.rows=rr=[Row(n,self,i) for i in range(n)] |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
573 for x in range(n): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
574 for y in range(n): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
575 self[(x,y)]=Cell(rr[y],y,cc[x],x) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
576 # Need cells in place for the following |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
577 for row,runs in zip(rr,runsPerRow): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
578 row.initRuns(runs) |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
579 for col,runs in zip(cc,runsPerCol): |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
580 col.initRuns(runs) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
581 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
|
582 for c in cc: |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
583 c.updateHeader(maxHeight=maxCRheight) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
584 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
|
585 for r in rr: |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
586 r.updateHeader(maxWidth=maxRRwidth) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
587 self.rowfmt="%s|%%s|"%(' '*maxRRwidth) |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
588 |
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
|
589 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 |
56 | 596 #=============new simple============ |
597 def pass0(self): # do columns of empty layout | |
598 for c in self.columns: | |
599 c.pass0() | |
57
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
600 for r in self.rows: |
057b52746850
use Run and Space classes in Vector.runs
Henry Thompson <ht@markup.co.uk>
parents:
56
diff
changeset
|
601 r.pass0() |
59 | 602 for c in self.columns: |
603 c.check0() | |
604 for r in self.rows: | |
605 r.check0() | |
56 | 606 |
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
|
607 def solve(self): |
56 | 608 self.pass0() |
609 print(self) | |
610 return | |
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
|
611 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
|
612 while someChanged>0: |
13 | 613 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
|
614 someChanged=0 |
13 | 615 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
|
616 for c in self.columns: |
13 | 617 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
|
618 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
|
619 print(self) |
13 | 620 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
|
621 for r in self.rows: |
13 | 622 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
|
623 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
|
624 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
|
625 |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
626 def dpush(s): |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
627 SOLVER.dp+=' ' |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
628 SOLVER.dstate.append(s) |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
629 |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
630 def dpop(s): |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
631 assert(SOLVER.dstate.pop()==s) |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
632 SOLVER.dp=SOLVER.dp[1:] |
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
633 |
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
|
634 def dprint(*args): |
16
a7a10e40b344
5a working after obvious bugfix,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
15
diff
changeset
|
635 print(SOLVER.dp,end='') |
14 | 636 print(*args) |
637 sys.stdout.flush() | |
638 | |
639 def eprint(*args,**kw): | |
640 print(*args,file=sys.stderr) | |
641 sys.stderr.flush() | |
59 | 642 print(SOLVER) |
643 breakpoint() | |
14 | 644 exit(kw['err']) |
645 | |
646 def wprint(*args): | |
647 print(*args,file=sys.stderr) | |
648 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
|
649 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
650 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
|
651 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
|
652 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
|
653 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
|
654 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
|
655 |
55
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
656 l = f.readline().rstrip() |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
657 vv=l.split('/') |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
658 n=int(len(vv)/2) |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
659 print('%sx%s puzzle'%(n,n),file=sys.stderr) |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
660 cols=[[int(i) for i in v.split('.')] for v in vv[:n]] |
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
661 rows=[[int(i) for i in v.split('.')] for v in vv[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
|
662 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
663 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
|
664 solver.solve() |
55
68004ce55703
convert to newer source of Nonogram data
Henry Thompson <ht@markup.co.uk>
parents:
17
diff
changeset
|
665 |