annotate nono.py @ 9:28a7b0e992cb

lots of fails in trace of 5a wrt checkNew/found0/foundN???
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 11 Mar 2020 22:06:04 +0000
parents 3276cf6ee6df
children 0a24625b33fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 #!/usr/bin/python3
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2 # Expects e.g. ^A copy from Nonograms dprint preview cols, then blank line, then rows
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3 # rows are space-separated
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 # cols are one-digit-after-another, unless some 2-digit, in which case x is separator
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5 # E.g.
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 # 13x1x2
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7 # 19
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 # maps to
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 # 13
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 # 1 1
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 # 2 9
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13 import sys
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 Red=''
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 eRed=''
9
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
17 RedFmt=Red+'%s'+eRed
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19 def interleave(*args):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 for vals in zip(*args):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 yield from vals
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23 class Vector(list):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 # reads top-to-bottom or left-to-right
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 def __init__(self,n,m,runs):
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 list.__init__(self,list(range(n)))
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 self.n=n
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)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 self.allRuns=list(self.seedList(0,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
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
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
52 def seedList(self,i,j,pos,runLen):
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
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
58 :param pos: left margin
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
59 :type pos: int
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
60 """
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
61 bound=self.n-(pos+runLen)+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
62 #dprint('s',i,j,pos,runLen,bound)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
63 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
64 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
65 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
66 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
67 for v in range(i,bound):
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 for sub in self.seedList(1,j+1,pos+v+r,runLen-(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
69 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
70
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 def step(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
72 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
73 wins=0
0
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
74 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
75 dprint('=====pass %s======'%k)
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
76 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
77 wins+=1
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
78 dprint(wins, scratch)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
79 newSeq=False
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
80 inSeq=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
81 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
82 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
83 # If blobby in _every_ pass, then must be a blob
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
84 if inSeq:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
85 newSeq=False
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
86 else:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
87 inSeq=True
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
88 newSeq=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
89 if self[i].val is None:
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
90 self.newBlob(i,newSeq)
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
91 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
92 # 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
93 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
94 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
95 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
96 exit(101)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
97 else:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
98 inSeq=newSeq=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
99
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 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
101 """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
102 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
103 """
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 i=i0 # starting index into self/scratch/maybe
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
105 maybe=[0]*(iBound-i0)
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
106 dprint('r: %s'%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
107 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
108 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
109 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
110 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
111 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
112 # 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
113 # (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
114 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
115 if self[k] is True:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
116 # 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
117 dprint('x0',k)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
118 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
119 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
120 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
121 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
122 # 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
123 # 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
124 # 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
125 # dprint('x1',i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
126 # 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
127 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
128 # 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
129 dprint('x2',i,iBound,req)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
130 return False
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
131 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
132 gapsFilled=0
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
133 dprint('top:',j)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
134 while rr>0:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
135 # 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
136 c=self[i].val
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
137 if c is False:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
138 dprint('x3',i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
139 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
140 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
141 # 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
142 gapsFilled+=1
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
143 # 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
144 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
145 i+=1
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
146 # Maybe a win?
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
147 # 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
148 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
149 dprint('x4',i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
150 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
151 # 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
152 # # 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
153 # 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
154 # raise Exception
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
155 # Victory!
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
156 dprint('c6',r,j,i)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
157 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
158 maybe[k]+=1
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
159 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
160 # 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
161 # 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
162 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
163 # 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
164 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
165 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
166 scratch[k]+=maybe[k]
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
167 return True
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
168 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
169
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
170 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
171 # 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
172 # 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
173 # non-marginal run, which is wrong if the length is unique and it's bounded...
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
174 changed=False
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
175 # 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
176 s=pos # start index of our run
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
177 while s>self.margin0 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
178 s-=1
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
179 f=pos # finish index of our run
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
180 while f<self.marginN and self[f+1].val is True:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
181 f+=1
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
182 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
183 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
184 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
185 if c==0:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
186 # not big enough yet
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
187 dprint('n0')
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
188 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
189 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
190 # is it safely left marginal, i.e. no blobs or big enough gaps before us?
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
191 if self.marginal(range(self.margin0,s),l):
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
192 changed=True
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
193 # mark our margins
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
194 for i in range(self.margin0+1,s):
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
195 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
196 self[i].setVal(False)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
197 if f<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
198 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
199 self[f+1].setVal(False)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
200 if f<self.marginN-2 and self[f+2].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
201 dprint('n1')
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
202 self.checkNew(f+2) # I think@@
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
203 self.found0(f) # pull in the start margin at least to f+2
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
204 if self.runs[-1]==l:
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
205 # is it safely _right_ marginal, i.e. no blobs or big enough gaps _after_ us?
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
206 if self.marginal(range(self.marginN-1,f,-1),l):
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 changed=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
208 # mark our margins
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
209 for i in range(self.marginN-1,f,-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
210 if self[i].val is None:
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
211 self[i].setVal(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
212 if s>self.margin0+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
213 if self[s-1].val is None:
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 self[s-1].setVal(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
215 if s>self.margin0+2 and self[s-2].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
216 dprint('n2')
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
217 self.checkNew(s-2) # I think@@
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
218 self.foundN(s) # pull in the finish margin at least to s-2
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
219 if changed:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
220 self.resetAllRuns()
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
221
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
222 def marginal(self,rng,l):
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
223 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
224 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
225 if self[i].val is True:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
226 return False
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
227 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
228 g=0
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
229 else:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
230 # None
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
231 g+=1
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
232 if g==l:
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
233 return False
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
234 return True
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
235
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
236 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
237 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
238 i=self.margin0
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
239 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
240 i+=1
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
241 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
242 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
243 self.initialComplete.append(r)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
244 self.margin0+=r+1
8
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
245 self.updateHeader(r=r)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
246
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 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
255 self.marginN-=r+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
256 self.updateHeader(r=r)
28a7b0e992cb lots of fails in trace of 5a wrt checkNew/found0/foundN???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 8
diff changeset
257
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
258
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
259 class Row(Vector):
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
260 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
261 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
262 self.y=pos
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
263 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
264
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
265 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
266 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
267 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
268
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
269 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
270 if maxWidth is None:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
271 # 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
272 if pre:
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 self.infix+=(RedFmt%r)+" "
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 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
275 # 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
276 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
277 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
278 else:
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
279 # init
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
280 self.maxWidth=maxWidth
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
281 self.prespace=' '*(maxWidth-self.width)
3276cf6ee6df vastly simplified onePass, printing rows working
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 7
diff changeset
282 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
283 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
284 self.suffix=""
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
285
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
286 def newBlob(self,x,newSeq):
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
287 self[x].setVal(True)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
288 self[x].column.checkNew(self.y)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
289 if newSeq:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
290 # We don't always check ourself, to avoid unnecessary duplication...
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
291 self.checkNew(x)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
292
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
293 class Column(Vector):
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
294 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
295 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
296 self.x=pos
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
297 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
298
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
299 def updateHeader(self,maxHeight):
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
300 self.maxHeight=maxHeight
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
301 self.fmt="%s%%s"%(' '*(maxHeight - self.height))
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
302 header=('-'.join(str(c) for c 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
303 self.header=self.fmt%header # pad to same 'height'
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
304
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
305 def newBlob(self,y,newSeq):
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
306 self[y].setVal(True)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
307 self[y].row.checkNew(self.x)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
308 if newSeq:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
309 # We don't always check ourself, to avoid unnecessary duplication...
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
310 self.checkNew(y)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
311
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
312 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
313 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
314 # 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
323 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
324 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
325
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
326 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
327 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
328
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
329 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
330 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
331 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
332 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
333 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
334 # 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
335 return
6
a56d5285575b drafted Vector.checkNew, still need found0 and foundN
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
336 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
337 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
338 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
339 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
340 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
341
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
342 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
343 # 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
344 def __init__(self,runsPerRow,runsPerCol):
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
345 n=self.n=len(runsPerCol)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
346 if n!=len(runsPerRow):
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
347 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
348 exit(1)
7
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
349 self.rc=runsPerRow
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
350 self.cc=runsPerCol
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
351 # 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
352 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
353 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
354 for c in cc:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
355 c.updateHeader(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
356 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
357 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
358 for r in rr:
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
359 r.updateHeader(maxRRwidth)
13f600be3a1b implemented newBlob and found0, refactoring display
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 6
diff changeset
360 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
361 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
362 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
363 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
364
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 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
366 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
367 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
368 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
369 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
370
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 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
372 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
373
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 __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
375 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
376 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
377 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
378 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
379
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
380 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
381
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 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391
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 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
393
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
394 solver=Nono(rows,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
395 print(solver)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
396 for c in solver.columns:
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
397 c.step()
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
398 print()
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
399 print(solver)
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
400 for r in solver.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
401 r.step()
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
402 print()
fee51ab07d09 blanket publication of all existing python files in lib/python on maritain
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
403 print(solver)