Maybe you'll like this.
f=: 13 :'y >.(1 |. 2 = y)*+:y'
f 1 2 3 2 2 4 2
2 2 6 4 2 8 2
f
] >. +: * 1 |. 2 = ]
Linda
-----Origina
l Messae-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Aai
Sent: Wednesday, May 14, 2014 2:45 AM
To: [email protected]
Subject: Re: [Jprogramming] ^: and boxes
I'm so sorry if this confuses you, but I enjoy composing (superfluous)
phrases like this. I hope you don't mind. :-)
On 13-05-14 19:31, 'Pascal Jasmin' via Programming wrote:
> Several interesting solutions, thank you.
>
> I understand the first 2 examples below:
>
> +:/ 1 2 3
> |domain error
>
> 2 */ 1 2 3
> 2 4 6
>
> this is definitely less clear:
> 2&*/ 1 2 3
> 24
>
> I guess this comes fromhttp://www.jsoftware.com/help/dictionary/d630n.htm
(dyad bond):
> 2 (2&*) 3
> 12
>
> At first I hated this form as needlessly confusing, but a fantastic
feature is that it turns ^: into a verb, and so as you have done, can apply
a modifier to it:
>
> 1 1 2 (2&*)"0 ] 12 2 3
> 24 4 12
>
>
>
>
> ----- Original Message -----
> From: Aai<[email protected]>
> To:[email protected]
> Cc:
> Sent: Tuesday, May 13, 2014 5:01:04 AM
> Subject: Re: [Jprogramming] ^: and boxes
>
> }. 2&*//.@(2&=,:]) 1 2 3 2 2 4 2 1
> 2 2 6 4 2 8 2 1
>
>
> On 12-05-14 19:11, 'Pascal Jasmin' via Programming wrote:
>> I'm looking for this answer, but a better way to do it.
>>
>> > ({~"1 0 [: i.#) (<@:+:@>)^:(1 |. 2= ] &>) ;/ 1 2 3 2 2 4 2 1
>> 2 2 6 4 2 8 2 1
>>
>> the right hand side must be boxed. Unboxing at end, just there for
display. Should not assume that it is possible for input.
>>
>> What the above is doing is if/for a cell that is equal to 2, double the
previous cell.
>>
>> To get it to work, I've had to generate a full n x n table, and then take
the diagonal. Is there a better tacit way that avoids n x n table?
>> ----------------------------------------------------------------------
>> For information about J forums seehttp://www.jsoftware.com/forums.htm
--
Met vriendelijke groet,
@@i = Arie Groeneveld
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm