Some more codes...
# Python codes:
unitlist = ([cross(rows, c) for c in cols] +
[cross(r, cols) for r in rows] +
[cross(rs, cs) for rs in ('ABC','DEF','GHI') for cs in
('123','456','789')])
units = dict((s, [u for u in unitlist if s in u])
for s in squares)
peers = dict((s, set(sum(units[s],[]))-set([s]))
for s in squares)
Run
I tried with...
# Nim codes:
var unitlist: seq[string] =
[for c in cols: cross(rows, cast[string](c))] +
[for r in rows: cross(r, cols)] +
[for rs in ("ABC","DEF","GHI"):
for cs in ("123","456","789"):
cross(rs, cs)]
var units = initTable[string](4):
for s in squares:
for u in unitlist:
if s in u:
{s, u}
var peers = initTable[string](4):
for s in squares:
{s, toHashSet(sum(units[s],[]))-toHashSet([s])
Run
But encountered lots of exceptions... :(
The documentation of Seq & Tables are very poor in Nim. Not many examples to
learn from.
Please help!