Andrew Nikitin wrote:
>
>
>> Viktor Cerovski viktor.cerovski at gmail.com
>> Thu Dec 17 09:45:52 HKT 2009
>>
>> Slightly shorter/faster/neater:
>>
>> mapply1=: 4 : 0
>> t=.ri=.0
>> while. (-.t) *. ri<#x do.
>> 'p s t'=.ri{x
>> y=.(s , (#p) }. ])&.((z i. 1)&|.)^:(f=.+./z=.p E. y) y
>> ri=.(-.f)*ri+1
>> end.
>> y
>> )
>
>
>
> As far as I understand, the loop will stop when it reaches terminating
> rule,
> regardless of whether it is applied or not, and that is not what should
> happen.
> To make it right you can do something like this.
>
>
>
> mapply3=: 4 : 0
> ri=.0
> while. ri<#x do.
> 'p s t'=.ri{x
> y=.(s , (#p) }. ])&.((z i. 1)&|.)^:(f=.+./z=.p E. y) y
> ri=.>:`(t * _:)@.f ri
> end.
> y
> )
>
mapply4=: 4 : 0
ri=.0
while. ri<#x do.
'p s t'=.ri{x
'y ri'=.((s , (#p) }. ])&.(j&|.)@>@{. ; t*_:)^:((#y)~:j=.i.&1 p E. y)
y;>:ri
end.
y
)
--
View this message in context:
http://old.nabble.com/Tacit-exercise-tp26832684s24193p26851395.html
Sent from the J Programming mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm