Thanks to Ric, Henery, and Raul for the occurrence count verbs. Here are their three examples:
Occurrence count verbs Ric Sherlock oc1=: <:@([: #/.~ ,)"1 Henry Rich oc2 =: +/@:="0 1"1 Raul Miller oc3=: _1 + ~.@[ #/.~@,"1 ] Here's a small test: Using the odometer verb: #a=.>:odo 6#6 46656 ts'(>:i.6) oc1 a' 0.0125646 4.19642e6 ts'(>:i.6) oc2 a' 0.0089258 4.19578e6 ts'(>:i.6) oc3 a' 0.0102935 4.19654e6 A larger test: #a=.>:odo 10#6 60466176 ts'(>:i.6) oc1 a' 37.6911 4.29497e9 ts'(>:i.6) oc2 a' 32.7673 4.29497e9 ts'(>:i.6) oc3 a' 42.1469 4.29497e9 So all of the verbs use roughly the same amount of memory, and all are fairly close in execution time, though Henry's version is a bit faster. Skip On Mon, Nov 4, 2019 at 1:07 AM Skip Cave <[email protected]> wrote: > NB. Generate multiple sets of 6 random integers from 1 to 6: > > ]m=:5 6$>:?30#6 > > 2 2 1 6 6 5 > > 6 5 6 6 6 6 > > 3 4 3 3 5 2 > > 1 2 6 4 3 1 > > 5 6 1 3 2 4 > > > NB. Use dyadic function oc (occurrence count) to calculate the occurrence > counts of > > NB. the integers in the right (y) argument, using the reference integer > set in the left {x} argument: > > > (>:i.6) oc m > > 1 2 0 0 1 2 > > 0 0 0 0 1 5 > > 0 1 3 1 0 1 > > 2 1 1 1 0 1 > > 1 1 1 1 1 1 > > > NB. If an integer in the x noun is not in the y noun, the result of oc > will be zero in that place. > > NB. If there is an integer in the y noun that is not in the x noun, it is > ignored. > > NB. What is oc? The verb 'oc' should allow for any length reference set (x > argument), > > NB. any width right argument, and any number of items (rows) > > > Skip > > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
