It looks like the function adds 1 to exactly one atom in the list on
every iteration, so
-&:(+/)&0 _2 0 0
applied to the list would tell you how many times you went through.
Henry Rich
On 12/7/2017 2:10 PM, 'Mike Day' via Programming wrote:
Thanks - I was hoping for something hiding within the ^: mechanism rather
than external, but it's a better option that what qjumpn does, which
is add
the count to the state variable. The latter keeps it local, at the
expense of
complicating the function a bit.
Cheers,
Mike
On 07/12/2017 17:12, Henry Rich wrote:
Increment a global variable.
Henry Rich
On 12/7/2017 11:15 AM, 'Mike Day' via Programming wrote:
But as you've got into the thread, Henry, do you see any way of
finding the number
of executions of u in u^:_ or u^:a: without keeping all the
intermediate results?
AOC 5 requires us to count the number of cycles, but we might as
well discard the
intermediates, as they are not required.
eg, for this problem I have a dyadic function qjumpn where x is the
right argument
for ^: .
_ qjumpn 0 3 0 1 _3 NB. just return the final value
5 5 2 5 0 1 _2
a: qjumpn 0 3 0 1 _3 NB. return all values
0 0 0 3 0 1 _3
0 1 1 3 0 1 _3
1 2 2 3 0 1 _3
4 3 2 4 0 1 _3
1 4 2 4 0 1 _2
5 5 2 5 0 1 _2
Now, as I'd taken the trouble to embed the count at index 1 in each
row,
the _ argument is adequate here, but we are really interested in
the last 5
items, in this example.
NB. only (?) way to count assuming it's not returned in the final row
<:@#a: qjumpn seq
5
In the actual problem presented in AOC 5, a considerable amount of
memory,
around 4.2 GB for "part 1" on my Windows laptop, is consumed using the
^:a: approach. (It would of course use slightly less memory if it
didn't include
that count element!)
Thanks,
Mike
On 07/12/2017 13:25, Henry Rich wrote:
Yes, I was. Serves me right for jumping into the middle of a
thread. Sorry.
Henry Rich
On 12/6/2017 10:18 PM, Raul Miller wrote:
Right - it's not a bug in J -- it's a bug in the sentence where
its result
conflicts with the advent of code day 5 spec.
I only just now realized that Henry must have thought I was
talking about a
J engine bug - but there's not one of those here.
Thanks,
---
This email has been checked for viruses by AVG.
http://www.avg.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm