Sorry, I should have read the specs more carefully.
Here is another attempt:
seq =: <"_1@|[EMAIL PROTECTED] , <@]
update =: (] ,(+&.> {:))/
a [EMAIL PROTECTED] m
┌───┬───┬───┬─────┬─────┬─────┐
│0 1│2 3│6 7│12 13│20 21│30 31│
│2 3│4 5│8 9│14 15│22 23│32 33│
└───┴───┴───┴─────┴─────┴─────┘
Steve
R.E. Boss wrote:
Notice
;/ 2 4 6 8 10 + recf i. 2 2 NB. ;/ is added for space reasons
+---+---+---+-----+-----+-----+
|0 1|2 3|6 7|12 13|20 21|30 31|
|2 3|4 5|8 9|14 15|22 23|32 33|
+---+---+---+-----+-----+-----+
whereas Phillips' (f/"1 @ ,.) does not meet the specs:
(<"_1[2 4 6 8 10) (+&.>/"1 @ ,.) <i. 2 2
+---+---+---+-----+-----+
|2 3|4 5|6 7| 8 9|10 11|
|4 5|6 7|8 9|10 11|12 13|
+---+---+---+-----+-----+
I would suggest
a ([:> [: f&.>/\.&.|. <@],<"[EMAIL PROTECTED]) m
so
;/ 2 4 6 8 10 ([:> [:+&.>/\.&.|. <@],<"[EMAIL PROTECTED]) i. 2 2 NB. ;/ is
extra
+---+---+---+-----+-----+-----+
|0 1|2 3|6 7|12 13|20 21|30 31|
|2 3|4 5|8 9|14 15|22 23|32 33|
+---+---+---+-----+-----+-----+
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Steven Phillips
Verzonden: vrijdag 12 mei 2006 5:05
Aan: Programming forum
Onderwerp: Re: [Jprogramming] 2 f 3 f 4 f m
Assuming m and the items of a are boxed, then
a (f/"1 @ ,.) m
where f has the form (g each).
Steve
Fraser Jackson wrote:
What is the simplest way of expressing the very commonly needed
form of which the subject line is an example:
a3 f a2 f a1 f m
a list of items a =. a1, a2, a3, ... applied successively with a
function f and a right argument m of a different shape or even of a
different type. This occurs with any sequential updating process.
The intermediate results are often of interest themselves. recf does
what I want, but is there a neater way?
recf=: 1 : 0
:
s =. y
r =. ,:y
for_i.
i. # x
do. s =. (i{x) u s
r =. r,s
end.
r
)
2 4 6 8 10 + recf i. 2 2
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm