I have a faster script which pre processes all the lines except the line.
Only the last line is executed at each step.
The boxing, lining up, and unboxing worries me, but this is a speed
improvement,
for me.
H =: 99 NB. can be any large value, like 1e6
L =: _1
D =: H, H, 1, H, 5, H, 8, H, 11, L, L, H, H, 20,3
P =: 1, 1, 1, 2, 4, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2
excP =: (1,L=])<;._1 L,[ NB. exclude L from P, then box
excD =: (1,L=])<;._1 L,] NB. exclude L from D, then box
expand =: (L~:D)&#inv!.L NB. expand result filling with L
PP =: (<@(+/\)@}.)\.each P excP D NB. box accumulated sections of P
DD =: P excD D NB. box sections of D wrt L
lineup =: -@#{.!.H every] NB. unboxes to line up along diagonal with fill H
expand;<./@lineup each DD([,+)each each PP
--
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm