# HG changeset patch # User Henry Thompson # Date 1754768914 14400 # Node ID 15e540c190d5616cfd8992a998ca2704a1640d4b # Parent eea4bcb657bc7f357a43976f2f2da3afc320196c derive Nono from list, not dict, and get [x,y] working diff -r eea4bcb657bc -r 15e540c190d5 nono.py --- a/nono.py Fri Jul 18 21:54:39 2025 +0100 +++ b/nono.py Sat Aug 09 15:48:34 2025 -0400 @@ -3,6 +3,22 @@ # > 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 +####### New Plan ####### +# All that matters is runs of incomplete cells. We begin with n+n runs, the maximum number is +# sum(len(rn) for rn in rows U cols) +# My own strategy seems to be FIFO for pass 0, then LIFO, for the queue of new/changed runs +# By cases, wrt types of change of a cell in its runs +# Change at the margin: +# New fill: complete the run and discard it, kill the other end and queue it +# dead: advance margin and add fill to any internal sequences of fills (always?), queue the new fill(s) +# Change in the middle +# New dead: If deterministic, split the run in two and requeue the cell (now in two runs) +# fill: If deterministic single gap at any end, kill, split, and requeue the cell (now in two runs) +#---------- +# Doesn't yet cover everything, e.g. killing gaps that are too small to be filled +# Do we need to actually represent run-internal segments, e.g. skips and bars? + + import sys Red='' @@ -263,9 +279,18 @@ self.val=v return True -class Nono(dict): +class Nono(list): + # 0,0 is upper left, so increasing y goes _downwards_, to match the standard layout - def __init__(self,runsPerRow,runsPerCol,debug): + def __getitem__(self,xy): + return list.__getitem__(self,xy[1])[xy[0]] + + def __setitem__(self,xy,v): + list.__getitem__(self,xy[1])[xy[0]] = v + + def __init__(self,runsPerRow: list[int], + runsPerCol: list[int], + debug: bool) -> list[list[Cell]]: global SOLVER self.loop=0 self.dp='' # old depth hack @@ -273,6 +298,7 @@ self.dstate=[] SOLVER=self n=self.n=len(runsPerCol) + list.__init__(self,list(list(list(range(n)) for _ in range(n)))) if n!=len(runsPerRow): print("losing r:%s x c:%s"%(len(runsPerRow),n),sys.stderr) exit(1) @@ -283,7 +309,7 @@ self.rows=rr=[Row(n,self,i) for i in range(n)] for x in range(n): for y in range(n): - self[(x,y)]=Cell(rr[y],y,cc[x],x) + self[x,y]=Cell(rr[y],y,cc[x],x) # Need cells in place for the following for row,runs in zip(rr,runsPerRow): row.initRuns(runs)