With n=5, is this what you are looking for? k,5#,:kk +-+-+-+-+-+ |a|b|c|d|e| +-+-+-+-+-+ |0|0|0|0|0| +-+-+-+-+-+ |0|0|0|0|0| +-+-+-+-+-+ |0|0|0|0|0| +-+-+-+-+-+ |0|0|0|0|0| +-+-+-+-+-+ |0|0|0|0|0| +-+-+-+-+-+
R.E. Boss > -----Oorspronkelijk bericht----- > Van: [EMAIL PROTECTED] [mailto:programming- > [EMAIL PROTECTED] Namens PackRat > Verzonden: zaterdag 3 mei 2008 21:37 > Aan: Programming forum > Onderwerp: [Jprogramming] BegQ--Adding variable number of rows without > 'for'loop? > > Related to the "NEW-merge-to-MASTER" question I had a while back, I'm > trying to write a generalized way of adding a variable number of rows > (columns eventually, via tranposing): > > j=. <array of boxed cells, where each row is a literal cell followed > by numeric cells> > n=. (1{($j))-1 NB. n is the number of data columns AFTER the first > > k=. 'a';'b';'c';'d';'e' NB. "toy" example > kk=. n$<0 > > What I'd like to be able to do is to create "n" rows (based on array > "j") of zero-filled boxes that are connected to list "k" (and then > transpose the resulting array to be used with array "j"). In other > words, I want code that automatically adjusts itself to an associated > array without having to write different versions for every type of > array we currently use. (After all, that's part of the point of > programming, isn't it?) What I've found through experimentation so far > is this: > > if n=1: k1=. (k,:kk) > if n=2: k2=. (k,:kk),kk > if n=3: k3=. (k,:kk),(kk,:kk) > if n=4: k4=. (k,:kk),(kk,:kk),kk > if n=5: k5=. (k,:kk),(kk,:kk),(kk,:kk) > if n=6: k6=. (k,:kk),(kk,:kk),(kk,:kk),kk > if n=7: k7=. (k,:kk),(kk,:kk),(kk,:kk),(kk,:kk) > etc. > > Although I see the pattern, I can't figure out how to express that > alternating coding pattern in J. Is there any way to express this (or > some other algorithm that achieves the same results) through some sort > of implicit loop or whatever, rather than through an explicit "for." > loop or something? > > What I'm looking for is some expression (or explicit verb definition) > that will automatically create "n" rows of boxed zeros connected to > list "k" of boxed data. (Additionally, perhaps a similar expression > could add "n" vectors of zeros to an existing numeric vector.) It > would seem that something like that ought to be possible, right? > Thanks in advance! > > Harvey > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
