On 21 February 2017 at 12:36, Joe Bogner <[email protected]> wrote:
> Hi Paul, what about using a loop?

Mostly because when I read the docs, the "traditional" stuff like
loops is not immediately obvious :-)

> I might consider making at conjunction if you intend to use this approach
> for other verbs:

Yes, it will need to take the verb as argument, so it'd need to be a
conjunction (something like "num_times accumulate verb" I guess).

> repeat =: 2 : 0
> :
> ret=.''
> for_i. i.v do.
> ret=. ret, x u y
> end.
> )
>
> 5 best3ofN repeat (5) 6
>
> 11 12 11 11 16

That's interesting, and looks like a pretty good start.

What I'd need to do though is, instead of just collecting all the
results, count them up. I'm not explaining well, sorry - I don't know
the terminology in J.

In a traditional language, I'd have a mapping - something like the
following pseudo-code.

result = {}
do 1000000 times:
    newval = verb()
    result[newval] = result[newval] + 1 # Needs a special case for the
first time we see a value.

return result

The key thing here is that I'm going to be collecting millions of
results, and I'll run out of memory if I just retain them all and
count at the end. But I'm not sure how to modify structures in J.

I guess I'd want an 2d array of value : count entries and each time
through the loop increment the appropriate row. I think I probably
need some variation on { and }, but the examples I've found in the
documentation are way to dense for me to work out how simple uses
would work :-(

Paul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to