[Jprogramming] more elegant solution?

R.E. Boss r.e.boss at outlook.com
Tue Dec 9 11:56:07 UTC 2014


Given the matrix 
   <:/~i.5 	NB. 5 could be any positive integer
1 1 1 1 1
0 1 1 1 1
0 0 1 1 1
0 0 0 1 1
0 0 0 0 1
I want to generate 
1  1  1  1  1
1  2  2  2  2
2  3  4  4  4
4  6  7  8  8
8 12 14 15 16
which one would expect to construct with
   ((+ +/),])/&.|.<:/~i.5
but then 
1 1 1 1 1 6 6 6 6 5 35 35 35 34 34 208 208 207 207 207 1245 1244 1244 1244
1244

Of course I can think of all kind of solutions of which 
   (3 : ('z=.(1-#y)}.y';'for_k. }.i.#y do. z=.z, (k{y) + +/z  end.';'z'))
<:/~i.5
I regard the most satisfactory.
Does anyone has a more elegant tacit solution then 
   (((+ +/),]),:^:(1=#@$))/&.|. <:/~i.5
1  1  1  1  1
1  2  2  2  2
2  3  4  4  4
4  6  7  8  8
8 12 14 15 16


R.E Boss



More information about the Programming mailing list