This should work:
import tables, strutils
proc cross(xs, ys: string): seq[string] =
for x in xs: (for y in ys: result.add x & y)
let
rows = "ABCDEFGHI"
cols = "123456789"
squares = cross(rows, cols)
var unitSeq: seq[string]
for c in cols: unitSeq.add cross(rows, $c)
for r in rows: unitSeq.add cross(cols, $r)
for rs in ["ABC", "DEF", "GHI"]: (for cs in ["123", "456", "789"]:
unitSeq.add cross(rs, cs))
var units, peers: Table[string, seq[string]]
for s in squares:
var tmp: seq[string]
for u in unitSeq: (if s in u: tmp.add u)
units[s] = tmp
if (let i = tmp.find s; i >= 0): tmp.del i
peers[s] = tmp
Run
- Nested list comprehension whospal
- Re: Nested list comprehension trtt
- Re: Nested list comprehension miran
- Re: Nested list comprehension whospal
- Re: Nested list comprehension whospal
- Re: Nested list comprehension dawkot
- Re: Nested list comprehension miran
- Re: Nested list comprehension miran
- Re: Nested list comprehension kaushalmodi
- Re: Nested list comprehension whospal
- Re: Nested list comprehension whospal
- Re: Nested list comprehension whospal
- Re: Nested list comprehension whospal
- Re: Nested list comprehension didlybom
- Re: Nested list comprehension dawkot
- Re: Nested list comprehension andrewgohlk
