2010/9/15 Markus Schmidt-Gröttrup <[email protected]>:
> toggle =: 4 : 0
> t =: -. t
> )
> t =: 0 NB. initialisation
> 1.03*300+1.025*200+1.02*100
> (+`* @. toggle)/ 1.03 300 1.025 200 1.02 100
You know that yields the right result only half the time, right?
(+`* @. toggle)/ 1.03 300 1.025 200 1.02 100
627.837
(+`* @. toggle)/ 1.03 300 1.025 200 1.02 100
6.06151e6
(+`* @. toggle)/ 1.03 300 1.025 200 1.02 100
627.837
Ways to do this computation are:
alt=: 1.03 300 1.025 200 1.02 100
*`+/ alt NB. argh, Mike was just a bit faster than me
627.837
> ({.@:[ * {:@:[ + ])&.:>/ (<0),~ _2<\ alt
627.837
3 :('r=.0';'for_b. y';'do. r=. ({.b) * ({:b) + r';'end.';'r') |._2]\ alt
627.837
3 :('r=.0';'while. #y';'do. ''f
d''=._2{.y';'y=._2}.y';'r=.f*d+r';'end.';'r') alt
627.837
+/d**/\f ['f d'=. |:_2]\ alt
627.837
([:+/(#~2|i.@:#)*[:*/\(0=2|i.@:#)#]) alt
627.837
Basically most of these are complicated by the fact that you have a
single array containing two kinds of data alternatingly, instead of
two different arrays, which I think would be more suitable.
Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm