> From: Alex Gian > Sent: Sunday, 29 August 2010 02:01 > > Thanks a lot for that Ric. > > I actually managed to get as far as this: > digits =. 10&#.inv > fp1 =. +! > spsum =. +/ @ |: @ fp1 @ digits > special =. = spsum > (#~ special)i.100000 > > which gave me 85837 correctly > also, > (#~ special)i.1000000 > 41086 408297 > gives the correct larger number in very acceptable time, the lower > number is incorrect because of the leading-zero prob already mentioned. > > I really hate what I had to do with the transpose to get the sum, > though, so I'll be studying your example rigorously. Seems to > eliminate all these probs.
If you add the "0 to digits, you don't need to use the transpose because +/ is only ever getting fed a list (rank 1). digits=: 10&#.^:_1"0 fp1=: + ! spsum=: +/@f...@digits special=: = spsum (#~ special) 1974 123 85837 408297 85837 408297 special f. = +/@(+ !)@(10&#.^:_1"0) IOW a one-liner for special would be: special2=: = +/@(+ !)@(10&#.^:_1"0) (#~ special2) 1974 123 85837 408297 85837 408297 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
