Here's my try at da y 5, it uses 3 boxes (pointer; iteration nr; memory
locations) and updates them and exits if the pointer goes out of bounds
using ^:cond^:_
Slow for sure, but it does complete in a reasonable time for both for part
1 and 2 on my mediocre phone.
Enjoy the deciphering!
i5=: fread '~temp/aoc2017/i5.txt'
NB. update for one iteration:
up=: newloc ; count ; updatemem
newloc =: ({. ([ +{)&> {:)
count =: ([: >: 1&{::)
updatemem =: {. >:@{`[`]}&> {:
cond=: ({. ((_1 < [) *. (< #))&> {:)
s5a=: 1 {:: [: up^:cond^:(_) 0;0;".;._2
up2=:newloc ; count ; umem2
umem2 =: {. >:`<:@.(3 <:])@{`[`]}&> {:
s5b=: 1 {:: [: up2^:cond^:(_) 0;0;".;._2
(s5a , s5b) i5
On 7 Dec 2017 06:54, "Arie Groeneveld" <[email protected]> wrote:
> Yes, that popped up when I was trying to get some sleep. Nothing is
> perfect. There is probably a stop possible in a construct like f ^: p ^:
> a: y.
>
> The count should be: <:@ # result.
>
>
> Op 07-12-17 om 00:00 schreef Raul Miller:
>
>> Bug, though, if end should have been caused by a negative offset.
>>
>> (Relies on ::] to end induction, but a range of negative indices won't
>> stop when specification says they should.)
>>
>> FYI,
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm