[acrossStarts=:<@I. 3 '#..'&-:\"1 '#',.data
+---++---++---++------++---++---++---+
|0 7||0 8||0 6||0 4 10||0 8||0 6||0 7|
+---++---++---++------++---++---++---+
[downStarts=:<@I. 3 '#..'&-:\"1 '#',.|:data
+---++---++---++-++----++---++---+
|0 6||0 8||0 4||1||0 10||0 6||0 8|
+---++---++---++-++----++---++---+
NB. downIns (see below) is a table of boxed pairs
NB. which gives index pairs of all the positions
NB. that require a puzzle index number for DOWN
NB. clues and I want to use each pair to
NB. place a 1 (or some marker) in an
NB. initially empty 13 by 13 table of boxes
emptyTable =: 13 13$a:
NB. using the j conjunction "amend".
NB. But I am struggling with preparing the
NB. input to the amend. That's where I need
NB. help.
NB. emptyTable does not have to be boxes at this
NB. point, it could just be zeroes, if that is
NB. easier. So a sparse array might be easier.
NB. Later the results in emptyTable could
NB. produce the boxed array.
NB.
NB. (startIns (not yet done) produces a similar
NB. parallel problem.)
NB.
NB. line wrap on next line
[downIns=:,.&.>/"_1(({~(*@#&>)#i.@#),:~" 1 0([:<"0 (*@#&>)#i.@#)) downStarts
+----+----+----+----+-----+----+----+
|0 0 |0 0 |0 0 |0 1 |0 0 |0 0 |0 0 |
|0 6 |0 8 |0 4 | |0 10 |0 6 |0 8 |
+----+----+----+----+-----+----+----+
|2 0 |2 0 |2 0 |2 1 |2 0 |2 0 |2 0 |
|2 6 |2 8 |2 4 | |2 10 |2 6 |2 8 |
+----+----+----+----+-----+----+----+
|4 0 |4 0 |4 0 |4 1 |4 0 |4 0 |4 0 |
|4 6 |4 8 |4 4 | |4 10 |4 6 |4 8 |
+----+----+----+----+-----+----+----+
|6 0 |6 0 |6 0 |6 1 |6 0 |6 0 |6 0 |
|6 6 |6 8 |6 4 | |6 10 |6 6 |6 8 |
+----+----+----+----+-----+----+----+
|8 0 |8 0 |8 0 |8 1 |8 0 |8 0 |8 0 |
|8 6 |8 8 |8 4 | |8 10 |8 6 |8 8 |
+----+----+----+----+-----+----+----+
|10 0|10 0|10 0|10 1|10 0|10 0|10 0|
|10 6|10 8|10 4| |10 10|10 6|10 8|
+----+----+----+----+-----+----+----+
|12 0|12 0|12 0|12 1|12 0|12 0|12 0|
|12 6|12 8|12 4| |12 10|12 6|12 8|
+----+----+----+----+-----+----+----+
NB. The example diagram supplied at rosettacode is flawed:
NB. there is a missing third row and the clue indices
NB. 9 and 10 do not appear, as a result.
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
On 1 Nov 2025, at 08:09, trx2358-discord via forum <fo...@jsoftware.com> wrote:
The rosetta example looks buggy to me. I got 3 down as being only length three from the initial diagram but the expanded one makes it look like it should be two.
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
I believe I have a solution for the amend problem. It is shown below.
grid=: 0 : 0
......#......
.#.#.#.#.#.#.
.......#.....
.#.###.#.#.#.
.....#.......
##.#.#.#.###.
...#.....#...
.###.#.#.#.##
.......#.....
.#.#.#.###.#.
.....#.......
.#.#.#.#.#.#.
......#......
)
$>LF cut grid
data=:>LF cut grid
[acrossStarts=:<@I. 3 '#..'&-:\"1 '#',.data
[downStarts=:<@I. 3 '#..'&-:\"1 '#',.|:data
emptyTable =: 13 13$a:
downIns=: ;/;(({~(*@#&>)#i.@#)(,.)each"0~" 1 ([:<"0 (*@#&>)#i.@#)) downStarts
9!:7'+++++++++|-'
(<1) downIns } emptyTable
+-+-+++-++-++-++-+++
|1| ||| ||1|| || |||
+-+-+++-++-++-++-+++
| | ||| || || || |||
+-+-+++-++-++-++-+++
|1| ||| || ||1|| |||
+-+-+++-++-++-++-+++
| | ||| || || || |||
+-+-+++-++-++-++-+++
|1| |||1|| || || |||
+-+-+++-++-++-++-+++
| | ||| || || || |||
+-+-+++-++-++-++-+++
| |1||| || || || |||
+-+-+++-++-++-++-+++
| | ||| || || || |||
+-+-+++-++-++-++-+++
|1| ||| || || ||1|||
+-+-+++-++-++-++-+++
| | ||| || || || |||
+-+-+++-++-++-++-+++
|1| ||| ||1|| || |||
+-+-+++-++-++-++-+++
| | ||| || || || |||
+-+-+++-++-++-++-+++
|1| ||| || ||1|| |||
+-+-+++-++-++-++-+++
This doesn't attempt to answer Brian's questions, as I'm not sure what they are.
Instead, it's my take on solving the proto-Rosetta problem.
I find it easier to analyse ravels of the grid, and its transpose. For this to work nicely,
it's best to border the grid with walls of blocked cells, eg a mini-grid such as
....
.#.#
....
.#.#
becomes
######
#....#
#.#.##
#....#
#.#.##
######
whose
across ravel is
#######....##.#.###....##.#.########
Examine the ravels for lights with 2 or more cells by pattern matching against
+----+-----+------+
|#..#|#...#|#....#| .......... etc
+----+-----+------+
Place 1s in a numerical grid for all the across lights, and do
the same with all
down lights, identified by similar pattern matching on the ravelled transpose.
Accumulate all light starting cells in the ravelled non-transposed grid. The lights'
lengths are easily found as they're the lengths of the matching patterns (less 2 for
the bounding '#' ).
Here's the code: (I THINK it's self-contained, but I might have omitted something!)
The input is in the format of Brian's example.
construct =: {{
NB. border grid with block characters #
s =. $ g =. h,. h, h,.~ y, h =. '#'
NB. create patterns for each possible light size > 1, eg
#...# for a light of 3 cells
NB. szs is array of possible sizes
pats =. {{ '#' 0 _1 } '.'#~y+2}} each szs =. }. >: i.
>./ s
NB. Block for across lights
NB. find indices of starts of across lights
apos =. g&{{ x&{{ >: I.(,x) E.~ y}} each y }} pats
NB. save lengths of across lights by suitable expanding szs
array
aszs =. szs#~ #every apos
apos =. ;apos
NB. set up a numeric grid with _1 for blocked cells, and 1 for
across start cells
new =. s $ 1 apos } - , g = h
NB. Block for down lights - just by working on transpose of
grid
NB. find indices of starts of down lights
dpos =. (|:g)&{{ x&{{ >: I.(,x) E.~ y}} each y }}
pats
NB. save lengths of down lights by suitable expanding szs array
dszs =. szs#~ #every dpos
dpos =. ;dpos
NB. Amend with 1s for down start cells
new =. |: (|.s) $ 1 dpos } ,|:new
NB. crosswords' "lights" are numbered from left to right and
then down,
NB. so accumulate the 1s for each start cell in the ravelled
array and then reshape
nums =. s $ (* +/\ ) 0 >. , new
NB. and recover the lists of across & down lights
anums =. apos { ,nums
dnums =. dpos { ,|: nums
NB. Assemble the expanded grid array applying cell verb to each
cell
NB. nums + 0 <. new combines light start cell numbers with
blocked cell indicators
boxch =. 9!:6 '' NB. Safer to use simple characters for bos
bounds - saving session box chars
9!:7 '+++++++++|-'
g =. cell each }."1 }:"1 }.}: nums + 0 <. new
NB. Assemble the list of Across & Down lights and their
lengths
clues =. (/:~) each (anums,.aszs);dnums,.dszs
clues =. ,/>('Across';'Down'),each {{ (":,.{."1 y) ,. ' ',.{{
'(',')',~":{:y }}"1 y}} each clues
NB. Output the whole
o =. (": g) , clues
9!:7 boxch NB. restore session box chars
o
}}
NB. output a blank, blocked or numbered cell
cell =: {{
NB. 2x4 internal shape seems to work quite nicely
2 4 cell y
:
select. y
case._1 do.
c =. x $'#'
case. 0 do.
c =. x $' '
case. do.
c =. x{. ' ',:~ ":y
end.
NB. '+||',. '---', NB. if doing own boxing
c
}}
And here's its output: (looks ok in fixed width in this draft):
NB. doing Brian's example, and couple of extreme cases
,.construct each grid; (1 1 $ '.') ; 1 1
$'#'
+------------------------------------------------------------------+
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||1 | |2 | |3 | |####|4 |5 | |6 | |7
||
|| | | | | | |####| | | | | |
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
|| |####| |####| |####|8 |####| |####| |####|
||
|| |####| |####| |####| |####| |####| |####|
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||9 | | | | | | |####|10 | | | |
||
|| | | | | | | |####| | | | |
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
|| |####| |####|####|####| |####| |####| |####|
||
|| |####| |####|####|####| |####| |####| |####|
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||11 | | | |12 |####|13 | | | | | |
||
|| | | | | |####| | | | | | |
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||####|####| |####| |####| |####| |####|####|####|
||
||####|####| |####| |####| |####| |####|####|####|
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||14 | | |####|15 | | | | |####|16 | |
||
|| | | |####| | | | | |####| | |
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
|| |####|####|####| |####| |####| |####|
|####|####||
|| |####|####|####| |####| |####| |####|
|####|####||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||17 | |18 | | | | |####|19 | | |
|20 ||
|| | | | | | | |####| | | | |
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
|| |####| |####| |####| |####|####|####| |####|
||
|| |####| |####| |####| |####|####|####| |####|
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||21 | | | | |####|22 | |23 | | | |
||
|| | | | | |####| | | | | | |
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
|| |####| |####| |####| |####| |####| |####|
||
|| |####| |####| |####| |####| |####| |####|
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
||24 | | | | | |####|25 | | | | |
||
|| | | | | | |####| | | | | |
||
|+----+----+----+----+----+----+----+----+----+----+----+----+----+|
|Across
|
| 1 (6)
|
| 4 (6)
|
| 9 (7)
|
|10 (5)
|
|11 (5)
|
|13 (7)
|
|14 (3)
|
|15 (5)
|
|16 (3)
|
|17 (7)
|
|19 (5)
|
|21 (5)
|
|22 (7)
|
|24 (6)
|
|25 (6)
|
|Down
|
| 1 (5)
|
| 2 (7)
|
| 3 (3)
|
| 5 (9)
|
| 6 (5)
|
| 7 (7)
|
| 8 (11)
|
|12 (9)
|
|14 (7)
|
|16 (7)
|
|18 (5)
|
|20 (5)
|
|23 (3)
|
|
|
|
|
+------------------------------------------------------------------+
|+----+
|
|| |
|
|| |
|
|+----+
|
|Across
|
|Down
|
+------------------------------------------------------------------+
|+----+
|
||####|
|
||####|
|
|+----+
|
|Across
|
|Down
|
+------------------------------------------------------------------+
There are probably some cases which lead to failure; 1x1 grids with a single dot or hash
seem to produce acceptable output.
It's a bit more prolix than I'd hoped. Any use?
Mike
$each construct each grid; (1 1 $ '.') ; 1 1 $'#'
┌─────┬───┬───┐
│553 6│6 6│6 6│
└─────┴───┴───┘
The only thing I did was to load your (saved) script and added the definition of grid:
grid=: 0 : 0
......#......
.#.#.#.#.#.#.
.......#.....
.#.###.#.#.#.
.....#.......
##.#.#.#.###.
...#.....#...
.###.#.#.#.##
.......#.....
.#.#.#.###.#.
.....#.......
.#.#.#.#.#.#.
......#......
)
JVERSION
Engine: j9.5.2/j64arm/darwin
Build: commercial/2024-02-02T18:38:04/clang-14-0-0/SLEEF=1
Library: 9.5.5
Platform: Darwin 64
Installer: j9.5 install
InstallPath: /users/brian/j9.5
Contact: www.jsoftware.com
Sorry - I should have included my definition of "grid" - my script expects
it to be a simple character array, whereas you've defined a character string
delimited by LF. So my code is handling what I think you regard as" > data "
So, after loading your copy of my script, I get:
$construct grid NB. ugh!
553 6
$construct > LF cut grid NB. what you need
72 66
APologies for blowing up your terminal screen!
Mike
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.