If you want one that works exactly like the others, replace }. in the code with |. . This is a much more elegant way to do it, but it requires moving the whole array around and more time and space (it is about three times slower).
Marshall -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Ben Gorte - LR Sent: Monday, January 24, 2011 2:14 AM To: Programming forum Subject: Re: [Jprogramming] Floating from Impressed again. I suppose I should start using that one in my application, However you were changing the specs. Your previous one is the real ffrom. Ben -----Original Message----- From: [email protected] on behalf of Marshall Lochbaum Sent: Mon 1/24/2011 1:18 AM To: 'Programming forum' Subject: Re: [Jprogramming] Floating from I have a better version! This one, despite an ugly for loop, uses more J array power and outperforms my previous attempt by an order of magnitude in time and space. ffrom=:4 :0"0 _ x=.,>x a=.(2"0 x) {. (<.x) }. y mult=. (,.~-.) (-<.) x for_m. mult do. a=. m +/@:* a end. a ) 6!:2 '(<?20$0) ffrom i.20#2' 0.0627697 7!:2 '(<?20$0) ffrom i.20#2' 75506048 Note that this one, because of its use of head, substitutes 0 for any value that is out of range. It also doesn't work for negative indices. Marshall ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
