Now write a single function called table . If:
a=:2 3 4
b=:0 1 2 3
then:
a table b
should product the same result you got. Everything is good so far.
Now write the function.
Table=:
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Björn Helgason
Sent: Sunday, November 20, 2011 5:42 AM
To: Programming forum
Subject: Re: [Jprogramming] table challenge in simple J
Ok it is simple j we are after
We start by defining a and b
a=: 2 3 5
b=: 0 1 2 3
Then we create the elements we want
'';b;a;a +/ b
┌┬───────┬─────┬───────┐
││0 1 2 3│2 3 5│2 3 4 5│
││ │ │3 4 5 6│
││ │ │5 6 7 8│
└┴───────┴─────┴───────┘
Now we rearrange a so it goes down in a column
'';b;(,.a);a +/ b
┌┬───────┬─┬───────┐
││0 1 2 3│2│2 3 4 5│
││ │3│3 4 5 6│
││ │5│5 6 7 8│
└┴───────┴─┴───────┘
Next we arrange it in a 2 by 2
('';b),.(,.a);a +/ b
┌───────┬───────┐
│ │2 │
│ │3 │
│ │5 │
├───────┼───────┤
│0 1 2 3│2 3 4 5│
│ │3 4 5 6│
│ │5 6 7 8│
└───────┴───────┘
ooppss wrong wa around we fix it with transpose
|:('';b),.(,.a);a +/ b
┌─┬───────┐
│ │0 1 2 3│
├─┼───────┤
│2│2 3 4 5│
│3│3 4 5 6│
│5│5 6 7 8│
└─┴───────┘
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm