Apologies to the forum for some excess empty messages on this thread which
seem to have appeared with my address.
The following is an executable script.
NB. simple table
Note''
Linda did not specify the time zone for displaying answers so I am using the
advantage of being in the time zone that begins the day to post from
an otherwise rather remote location in the south west pacific.
I wondered what Linda, as a retired teacher, wanted to
demonstrate with this simple problem.
For me,
(1) J is elegant at combining simple elements into
more complex structures
(2) , and its relatives ,. ,: and ; are arguably
its most significant verbs. (A simple empirical
study suggests that , is the most frequently used J verb.)
A simple problem exploring them is useful.
(3) Time is precious and a very (and perhaps the most)
economical solution in terms of time and required thought
is to use those simple verbs and just write down the
required train.
Using a top down approach, I do the first line, then laminate
the bottom line for the result.
)
tab =: ('';]) ,: ([:,.[);*/
NB. Alternatively starting left to right
tab1 =: ('';[:,.[) ,. ];*/
1 2 3 tab 4 5 6
1 2 3 tab1 4 5 6
Note 'continued'
This is a key lesson for J newbies. The language provides tools
for efficient execution of the total task. We do not need to know
all the ways of doing something to do it efficiently and well.
(4) There will be lots of other solutions probably using other verbs.
They will show that for people with different background and
intuitive ways of thinking, there are also simple ways
of expressing their ideas in J.
(5) A solution only using , and ; and rank and references
to the arguments is easy as users develop experience of the
power of the rank conjunction.
To convert a vector to a one column array we can use ,"0
To use it in trains we need reference to the argument
as well so use [: ,"0 [
Here the ,"0 attaches the whole of the right argument to the
atoms of the left argument. An empty left argument provides
a default case transforming a row to a column.
)
v =: (''; [: ,"0 [),"0 ];*/
NB. the use of the insert can be also be removed by using rank
v2 =: (''; [: ,"0 [),"0 ]; *"0 _
1 2 3 v 3 4 5
1 2 3 v2 3 4 5
Note 'Final'
Linda, I am looking forward to other solutions, and your 'hints'
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm