I won't bore you with my code - also very loopy - took 2min 12sec for part 2!
Only ~1.2 sec for part 1.

Using 13 : 'code' I made a power form for part 1,  called it qjump (for "quick" jump) which worked fine for the example,  but it was far from quick for the given problem, failing to terminate before I gave up on it.   (However,  Arie Groeneveld's tacit version (just received) takes only about 7.3 sec for part 1,  though it uses a lot of space,
~6 GB. )

The long execution time for part 2 seems surprising,  though I suppose it is doing about 200k loops every second.  Like Raul,  I used the _1^ condition method of incrementing
or decrementing.

But I wonder if there's a short-cut?    Are we all using indexed look-up and assignment? My test input had only 1043 elements;   is there a matrix method out there?   Incrementing the whole set with a boolean with a single 1 in the current position, ie a row from the identity matrix, almost triples the execution time (for part 1),  so probably not!

Probably runs in no time in good old Fortran,  and other compiled PLs.

Mike




On 06/12/2017 14:36, Raul Miller wrote:
My part 2 replaced the line updating y with
     y=. (off+_1^off>2) ndx} y

It's probably worth mentioning, for people not familiar with the
_1^test mechanism (if test is true, that's _1, if it's false, that's 1
- conditionally negating a sub-expression happens often enough that
this is worth knowing).

Thanks,



---
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

Reply via email to