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,
--
Raul
On Wed, Dec 6, 2017 at 8:53 AM, Joe Bogner <[email protected]> wrote:
> Mine is also similar --
>
> In previous years I did a tacit only solution to something similar:
> http://code.jsoftware.com/wiki/User:Joe_Bogner/ByteCodeInterpreter but
> opted for the simpler approach here
>
> I used a MAXGUARD early on to make sure my loop didn't run away -- although
> I could have just used jbreak. Unnecessary globals are also left in there.
>
> MAXGUARD=:50000000
>
> NB. http://www.jsoftware.com/pipermail/programming/2014-July/037999.html
> amend=: (0:{::])`(1:{::])`(2:{::])}~
>
>
> inc =: (# input) # 0
> blank =: (# input) # 0
> jmp =: 0
>
> run =: 3 : 0
> steps =: 0
> ip =: 0
> running =: 1
>
> while. (steps < MAXGUARD) *. running do.
>
>
> jmp =: (ip { input) + (ip { inc)
> inc =: (amend 1;ip;blank) + inc
>
> ip =: ip + jmp
>
> NB. smoutput (steps;jmp;ip;(inc+input))
>
>
> steps=: >: steps
>
> if. ip >: (#input) do. running=: 0 end.
> end.
> smoutput steps
> )
>
> run2 =: 3 : 0
> steps =: 0
> ip =: 0
> running =: 1
>
> while. (steps < MAXGUARD) *. running do.
>
>
> jmp =: (ip { input) + (ip { inc)
>
> if. jmp >: 3 do.
> inc =: (amend _1;ip;blank) + inc
> else.
> inc =: (amend 1;ip;blank) + inc
> end.
>
> ip =: ip + jmp
>
> NB. smoutput (steps;jmp;ip;(inc+input))
>
>
> steps=: >: steps
>
> if. ip >: (#input) do. running=: 0 end.
> end.
> smoutput steps
> NB. smoutput (steps;jmp;ip;(inc+input))
> )
>
>
> run2 ''
>
> On Tue, Dec 5, 2017 at 6:09 PM, Raul Miller <[email protected]> wrote:
>
>> Mine's similar:
>>
>> steps=:3 :0
>> bounds=. _1+0,#y
>> cnt=. 1+ndx=. 0
>> while. 1=bounds I. nxt=. ndx+off=. ndx{y do.
>> y=. (1+off) ndx} y
>> ndx=. nxt
>> cnt=. 1+cnt
>> end.
>> )
>>
>> But part 2 was only required another 7 characters, so there's that
>> (though it also took over 70 times as many steps to complete.)
>>
>> That said, I should perhaps note that my leaderboard score is 0 - I'm
>> waiting plenty of time before trying these things.
>>
>> --
>> Raul
>>
>> On Tue, Dec 5, 2017 at 5:05 PM, Ric Sherlock <[email protected]> wrote:
>> > Did anyone come up with a nice Jish solution for this?
>> >
>> > Mine (see below) ended up being very scalar.
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > countJumps=: 3 :0
>> >
>> > count=. idx=. 0
>> >
>> > offsets=. y
>> >
>> > while. (0 <: idx) *. (idx < #offsets) do.
>> >
>> > count=. count + 1
>> >
>> > idx_new=. idx ([ + {) offsets
>> >
>> > offsets=. idx (1 + {)`[`]} offsets
>> >
>> > idx=. idx_new
>> >
>> > end.
>> >
>> > count;idx;offsets
>> >
>> > )
>> >
>> >
>> > countJumps 0 3 0 1 _3
>> >
>> > 5
>> > ----------------------------------------------------------------------
>> > 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