In Essays/Odometer a method of generating the odometer of a set of values directly is missing.
Suppose we want all selections of 2 3 5 7 . Then, with the help of the verb odometer from that essay, we get

   odometer=: #: i.@(*/)
   $(odometer 4 # 4){ 2 3 5 7
256 4
   10 20 30 40{(odometer 4 # 4){ 2 3 5 7
2 2 5 5
2 3 3 2
2 3 7 5
2 5 5 2

But this can be done directly as well.

   $([:,/,"1/)^:3~ ,.2 3 5 7
256 4
   10 20 30 40{([:,/,"1/)^:3~ ,.2 3 5 7
2 2 5 5
2 3 3 2
2 3 7 5
2 5 5 2

However, odometer is more efficient:

odomtr=: 4 : 0
join=. [: ,/ ,"1/
join ^:(x-1) ~ ,.y
)

   ('odometer';'odomtr')dspl rnkng scores '(odometer 11 # 4) { t'; '11 odomtr t' [t=:2 3 5 7
+--------+----+-----+----+----+
|verb    |rank|et*sz|time|size|
+--------+----+-----+----+----+
|odometer| 0  |1.00 |1.00|1.00|
+--------+----+-----+----+----+
|odomtr  | 1  |2.13 |1.89|1.13|
+--------+----+-----+----+----+

   ((odometer 11 # 4) { t) -: 11 odomtr t=:2 3 5 7
1

But what if we want to make certain selections? In our verb it can be done on the fly, whereas in odometer it has to be done afterwards. Then the performance balance swings the other way.
In the next example we select the ones in which all numbers differ. Other selections can be thought of.

   join=. [: ,/ ,"1/

   ('odometer';' ')dspl rnkng scores '((#~(-:~.)"1) odometer 6 # 10){ t';'([:(#~(-:~.)"1) join)^:5~ ,. t'[t=:2 3 5 7 11 13 17 19 23 29
+--------+----+-----+----+----+
|verb    |rank|et*sz|time|size|
+--------+----+-----+----+----+
|odometer| 1  |5.10 |2.17|2.35|
+--------+----+-----+----+----+
|        | 0  |1.00 |1.00|1.00|
+--------+----+-----+----+----+

   (((#~(-:~.)"1) odometer 6 # 10){ t)-:([:(#~(-:~.)"1) join)^:5~ ,. t
1

Applying repeated squaring makes the process more efficient, but not enough to threaten odometer .

odomtrs=: 4 : 0
join=. [: ,/ ,"1/
> join&.>/ join~ &.> ^:(I.|.#:x) <,.y
)

   ('odometer';'odomtrs';'odomtr')dspl rnkng scores '(odometer 10 # 4){2 3 5 7';'10 odomtrs 2 3 5 7'; '10 odomtr 2 3 5 7'
+--------+----+-----+----+----+
|verb    |rank|et*sz|time|size|
+--------+----+-----+----+----+
|odometer| 0  |1.00 |1.00|1.00|
+--------+----+-----+----+----+
|odomtrs | 1  |2.06 |2.00|1.03|
+--------+----+-----+----+----+
|odomtr  | 2  |3.04 |2.70|1.13|
+--------+----+-----+----+----+

RE Boss/J-blog/Odometer (last edited 2010-02-21 21:24:38 by RE Boss)