Mercurial > hg > python
changeset 61:19262b15a099
merge
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Wed, 13 Dec 2023 17:32:38 +0000 |
parents | bc1acb1416ab (current diff) 68004ce55703 (diff) |
children | c82a8743fd48 |
files | |
diffstat | 1 files changed, 14 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/nono.py Wed Dec 13 17:31:28 2023 +0000 +++ b/nono.py Wed Dec 13 17:32:38 2023 +0000 @@ -9,6 +9,10 @@ # 13 # 1 1 # 2 9 +# New version, input taken from Nonograms Outer HTML plus +# > fgrep 'task = ' nono10.xhtml|tr ';' '\n' | fgrep task\ = | sed 's/^.*= //'| tr -d \' +# E.g. 8/5.1/2.3/2.1/4.3/3.4/2/1.1/3/5.2/2.2/2.2/1.3.2/5.1/3.1.1/2/2.3.1/7.1/1.1.2/3.2 + import sys @@ -24,8 +28,8 @@ # reads top-to-bottom or left-to-right def __init__(self,n,m,runs): list.__init__(self,list(range(n))) - self.n=n - self.m=m + self.n=n # size + self.m=m # parent NoNo self.margin0=0 # a run can start here, so if >0 then self[m0-1].val must be False self.marginN=n-1 # a run can end here, so if <n-1 then self[mN+1].val ditto self.runs=self.origRuns=runs @@ -60,6 +64,7 @@ :type pos0: int :param posN: right margin :type posN: int + :return: list of runlens separated, possibly prefixed, with skips as negative integers """ bound=posN-(pos0+runLen)+1 dprint('s',i,j,pos0,posN,runLen,bound) @@ -536,19 +541,13 @@ else: f=sys.stdin - cols=[] - - for l in f: - l=l.rstrip() - if l=='': - break - if 'x' in l: - vv=[int(s) for s in l.split('x')] - else: - vv=[int(c) for c in l] - cols.append(vv) - - rows=[[int(s) for s in l.split()] for l in f] + l = f.readline().rstrip() + vv=l.split('/') + n=int(len(vv)/2) + print('%sx%s puzzle'%(n,n),file=sys.stderr) + cols=[[int(i) for i in v.split('.')] for v in vv[:n]] + rows=[[int(i) for i in v.split('.')] for v in vv[n:]] solver=Nono(rows,cols) solver.solve() +