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

Reply via email to