Mercurial > hg > python
annotate nono.py @ 12:ede2551ae7d9
red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Sun, 15 Mar 2020 19:08:44 +0000 |
parents | 1b9daa849b0f |
children | 70993b538ddb |
rev | line source |
---|---|
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
1 #!/usr/bin/python3 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
2 # Expects e.g. ^A copy from Nonograms dprint preview cols, then blank line, then rows |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
3 # rows are space-separated |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
4 # cols are one-digit-after-another, unless some 2-digit, in which case x is separator |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
5 # E.g. |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
6 # 13x1x2 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
7 # 19 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
8 # maps to |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
9 # 13 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
10 # 1 1 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
11 # 2 9 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
12 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
13 import sys |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
14 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
15 Red='[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
|
16 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
|
17 RedFmt=Red+'%s'+eRed |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
18 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
19 def interleave(*args): |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
20 for vals in zip(*args): |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
21 yield from vals |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
22 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
23 class Vector(list): |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
24 # reads top-to-bottom or left-to-right |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
25 def __init__(self,n,m,runs): |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
26 list.__init__(self,list(range(n))) |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
27 self.n=n |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
28 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
|
29 self.marginN=n-1 # a run can end here, so if <n-1 then self[mN+1].val ditto |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
30 self.runs=self.origRuns=runs |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
31 self.initialComplete=[] |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
32 self.finalComplete=[] |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
33 self.resetAllRuns() |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
34 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
35 def __repr__(self): |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
36 return "V@%s%s:%s"%(self.x,self.origRuns,list.__repr__(self)) |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
37 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
38 def __str__(self): |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
39 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
|
40 |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
41 def myPrintSize(self): |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
42 return sum(len(str(run)) for run in self.runs)+len(self.runs)-1 |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
43 |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
44 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
|
45 # 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 |
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
|
52 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
|
53 """ |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
54 :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
|
55 :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
|
56 :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
|
57 :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
|
58 :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
|
59 :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
|
60 :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
|
61 :type posN: int |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
62 """ |
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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
73 def step(self): |
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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 for k,runs in enumerate(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
|
80 dprint('=====pass %s======'%k) |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
81 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
|
82 wins+=1 |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
83 dprint(wins, scratch) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
84 maybeSeq=None |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
85 inSeq=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
|
86 for i in range(self.n): |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
87 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
|
88 # 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
|
89 if inSeq is None: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
90 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
|
91 dprint('s1',inSeq) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
92 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
|
93 if self[i].val is None: |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
94 self.newBlob(i,True) # Check cross-vector |
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
|
95 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
|
96 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
|
97 # already there |
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 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
|
99 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
|
100 print("Shouldn't happen: attempt to blob where x already present! %s at %s"%(self,i),file=sys.stderr) |
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 exit(101) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
102 elif inSeq is not None: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
103 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
|
104 inSeq=None |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
105 maybeSeq=None |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
106 dprint('s2',i-1) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
107 self.checkNew(i-1) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
108 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
|
109 dprint('s3',i) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
110 maybeSeq=i |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
111 dprint('s4',inSeq,i) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
112 if inSeq is not None: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
113 self.checkNew(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
|
114 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
|
115 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
116 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
|
117 """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
|
118 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
|
119 """ |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 # 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
|
129 # (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
|
130 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
|
131 if self[k] is True: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
132 # 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
|
133 dprint('x0',k) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 # 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
|
139 # 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
|
140 # 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
|
141 # dprint('x1',i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
142 # 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
|
143 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
|
144 # 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
|
145 dprint('x2',i,iBound,req) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
146 return False |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
147 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
|
148 gapsFilled=0 |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
149 dprint('top:',j) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
150 while rr>0: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
151 # 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
|
152 c=self[i].val |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
153 if c is False: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
154 dprint('x3',i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
155 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
|
156 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
|
157 # 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
|
158 gapsFilled+=1 |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
159 # 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
|
160 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
|
161 i+=1 |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
162 # Maybe a win? |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
163 # 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
|
164 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
|
165 dprint('x4',i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
166 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
|
167 # 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
|
168 # # 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
|
169 # 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
|
170 # raise Exception |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
171 # Victory! |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
172 dprint('c6',r,j,i) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
173 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
|
174 maybe[k]+=1 |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
175 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
|
176 # 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
|
177 # 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
|
178 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
|
179 # 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
|
180 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
|
181 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
|
182 scratch[k]+=maybe[k] |
8
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
183 return True |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
184 print("Shouldn't happen? - fell through",stack,i,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
|
185 |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
186 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
|
187 # 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
|
188 # 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
|
189 # non-marginal run, which is wrong if the length is unique and it's bounded... |
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
|
190 start0=0 if self.margin0==0 else self.margin0+1 |
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
|
191 startN=self.marginN if (self.marginN==self.n-1) else self.marginN-1 |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
192 changed=False |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
193 # 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
|
194 s=pos # start index of our run |
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
|
195 while s>start0 and self[s-1].val is True: |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
196 s-=1 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
197 f=pos # finish index of our run |
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
|
198 while f<startN and self[f+1].val is True: |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
199 f+=1 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
200 l=(f-s)+1 # our length |
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
|
201 print('%s:%s,%s,%s,%s:<%s>'%(str(self.__class__.__name__)[0],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
|
202 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
|
203 if c==0: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
204 # not big enough yet |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
205 dprint('x0') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
206 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
|
207 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
|
208 # 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
|
209 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
|
210 changed=True |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
211 dprint('n1') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
212 # mark our margins |
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
|
213 for i in range(start0,s): |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
214 if self[i].val is None: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
215 self[i].setVal(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
|
216 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
|
217 if self[f+1].val is None: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
218 self[f+1].setVal(False) |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
219 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
|
220 else: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 # 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
|
225 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
|
226 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
|
227 dprint('n2') |
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
|
228 # mark our margins |
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
|
229 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
|
230 if self[i].val is None: |
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
|
231 self[i].setVal(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
|
232 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
|
233 if self[s-1].val is None: |
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
|
234 self[s-1].setVal(False) |
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
|
235 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
|
236 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
|
237 dprint('x2a') |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
238 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
|
239 dprint('x2b') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
240 if changed: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
241 self.resetAllRuns() |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
242 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
243 def marginal(self,rng,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
|
244 print('m',rng.start,rng.stop,rng.step) |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
245 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
|
246 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
|
247 if self[i].val is True: |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
248 dprint('mx0') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
249 return False |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
250 if self[i].val is False: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
251 g=0 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
252 else: |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
253 # None |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
254 g+=1 |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
255 if g==l: |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
256 dprint('mx1') |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
257 return False |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
258 return True |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
259 |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
260 def found0(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
|
261 print('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
|
262 i=self.margin0 |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
263 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
|
264 i+=1 |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
265 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
|
266 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
|
267 self.initialComplete.append(r) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
268 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
|
269 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
|
270 |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
271 def foundN(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
|
272 print('foundN called on %s at %s'%(self,i)) |
28a7b0e992cb
lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
8
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
282 |
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
|
283 class Row(Vector): |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
284 def __init__(self,n,m,runs,pos): |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
285 Vector.__init__(self,n,m,runs) |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
286 self.y=pos |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
287 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
|
288 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
289 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
|
290 return ((self.fmt%(' '.join(str(r) for r in self.runs)))+ |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
291 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
|
292 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
293 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
|
294 if maxWidth is None: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
295 # update |
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
|
296 if pre: |
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
|
297 self.infix+=(RedFmt%r)+(" " 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
|
298 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
|
299 # post |
28a7b0e992cb
lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
8
diff
changeset
|
300 self.suffix=" "+RedFmt%r+self.suffix |
28a7b0e992cb
lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
8
diff
changeset
|
301 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
|
302 else: |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
303 # init |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
304 self.maxWidth=maxWidth |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
305 self.prespace=' '*(maxWidth-self.width) |
3276cf6ee6df
vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
7
diff
changeset
|
306 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
|
307 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
|
308 self.suffix="" |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
309 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
310 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
|
311 self[x].setVal(True) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
312 if crossCheck: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
313 self[x].column.checkNew(self.y) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
314 |
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
|
315 class Column(Vector): |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
316 def __init__(self,n,m,runs,pos): |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
317 Vector.__init__(self,n,m,runs) |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
318 self.x=pos |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
319 self.height=self.myPrintSize() |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
320 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
321 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
|
322 dprint('CuH',r,pre) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
323 if maxHeight is None: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
324 # update |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
325 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
|
326 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
|
327 self.infix.append(RedFmt%rc) |
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
|
328 self.infix.append("-" if self.runs else "") |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
329 else: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
330 # post |
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
|
331 ins=["-"] |
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
|
332 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
|
333 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
|
334 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
|
335 dprint('CuH1: |%s|,%s,%s,%s'%(self.prespace,self.infix,self.suffix,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
|
336 self.header=(["-"]*self.prespace)+\ |
1b9daa849b0f
A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
337 self.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
|
338 ['-'.join(str(c) for c in 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
|
339 self.suffix |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
340 else: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
341 # init |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 self.fmt="%s%%s"%(' '*self.prespace) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
347 header=('-'.join(str(c) for c in self.runs)) |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
348 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
|
349 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
|
350 |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
351 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
|
352 self[y].setVal(True) |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
353 if crossCheck: |
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
354 self[y].row.checkNew(self.x) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
355 |
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
|
356 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
|
357 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
|
358 # 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
367 def __repr__(self): |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
368 return "C@(%s,%s):%s"%(self.x,self.y,self.val) |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
369 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
370 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
|
371 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
|
372 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
373 def setVal(self,v): |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
374 if v is True: |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
375 if self.val is False: |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
376 print("Warning: x -> * at %s,%s"%(self.x,self.y),file=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
|
377 elif self.val is True: |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
378 # No-op |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
379 return |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
380 self.val=v |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
381 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
|
382 if self.val is not None: |
6
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
383 print("Warning: %s -> %s at %s,%s"%(self.val,v,self.x,self.y),file=sys.stderr) |
a56d5285575b
drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
0
diff
changeset
|
384 self.val=v |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
385 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
386 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
|
387 # 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
|
388 def __init__(self,runsPerRow,runsPerCol): |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
389 n=self.n=len(runsPerCol) |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
390 if n!=len(runsPerRow): |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
391 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
|
392 exit(1) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
393 self.rc=runsPerRow |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
394 self.cc=runsPerCol |
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
395 # print col nums>9 vertically :-( |
9
28a7b0e992cb
lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
8
diff
changeset
|
396 self.columns=cc=[Column(n,self,runsPerCol[i],i) for i in range(n)] |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
397 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
|
398 for c in cc: |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
399 c.updateHeader(maxHeight=maxCRheight) |
9
28a7b0e992cb
lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
8
diff
changeset
|
400 self.rows=rr=[Row(n,self,runsPerRow[i],i) for i in range(n)] |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
401 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
|
402 for r in rr: |
10
0a24625b33fa
checkNew improving, reverse pass failing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
9
diff
changeset
|
403 r.updateHeader(maxWidth=maxRRwidth) |
7
13f600be3a1b
implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
6
diff
changeset
|
404 self.rowfmt="%s|%%s|"%(' '*maxRRwidth) |
9
28a7b0e992cb
lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
8
diff
changeset
|
405 for x in range(n): |
28a7b0e992cb
lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
8
diff
changeset
|
406 for y in range(n): |
0
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
407 self[(x,y)]=Cell(rr[y],y,cc[x],x) |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
408 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 |
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
|
415 def solve(self): |
1b9daa849b0f
A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
416 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
|
417 while someChanged>0: |
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
|
418 someChanged=0 |
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
|
419 for c in self.columns: |
1b9daa849b0f
A bit further: red col working, finding middle of row 1, formatting off, outer loop in place, but fails overall after 3rd pass achieves nothing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
420 someChanged+=c.step() |
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
|
421 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
|
422 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
|
423 for r in self.rows: |
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
|
424 someChanged+=r.step() |
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
|
425 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
|
426 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
|
427 |
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
|
428 def dprint(*args): |
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
|
429 print(*args) |
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
|
430 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 |
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 cols=[] |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
438 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
439 for l in f: |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
440 l=l.rstrip() |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
441 if l=='': |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
442 break |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
443 if 'x' in l: |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
444 vv=[int(s) for s in l.split('x')] |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
445 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
|
446 vv=[int(c) for c in l] |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
447 cols.append(vv) |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
448 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
449 rows=[[int(s) for s in l.split()] for l in f] |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
450 |
fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
451 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
|
452 solver.solve() |