I wrote:
> Some experiments show that x&i. doesn't do any special
> magic when #x is large yet #~.x is small. But it could.
I should have pointed out that Roger's solution is still more than twice as
fast & lean as the other contenders, irrespective of
whether this optimization is implemented or not.
db0 =: (, 10 | 0 - 1 3 1 7 3 9 +/@:* ])&.(sn i. |:)
db1 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)
hr0 =: (, 10 | 9 7 9 3 7 1 +/@:* ])&.(sn i. |:)
NB. 9 7 9 3 7 1 -: 10 - 1 3 1 7 3 9
rh0 =: (,"1 0 (841 $ '0987654321') {~ 1 3 1 7 3 9 +/ .*~ sn
i. ]) NB. 841 -: 1 3 1 7 3 9 (1 + [ +/@:*
(#<:)&:# ) sn
contenders =: db0`db1`hr0`rh0
A =: sn {~ ? 4e6 6 $ #sn
NB. Big array of SEDOLs
assert (-: 1&|.) contenders `:0 A
NB. Results all match
ts =: 6!:2 , 7!:2@:]
scores =: 3 : 'y (5!:0) 1 : '' 10 ts ''''u A'''' '' '"0
contenders
scores /:~ ;:^:_1 contenders ,. '0.2' 8!:0 (%"1<./) scores
rh0 1.00 1.00
hr0 2.33 1.55
db0 2.40 1.55
db1 2.68 1.73
In the results, the numbers are expressed as factors of the best score (so
lower is better, and 1 is best), with the first
column of numbers being time, and the second space.
So, Chito, if you're still reading this thread, and speed is your metric, you
should choose Roger's verb.
(Though, given that the difference in time between the fastest and slowest
expressions is only 0.8 seconds for 4 million SEDOLS,
you can probably afford to select any of them for any reason that strikes you.
If you're processing 4 million records,
calculating the checksum is unlikely to be a bottleneck.)
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm