Given an arbitrary sequence of numbers, for example
   a=: 1 1 1 3 3 3 4 4 4 3 3 3 5 5 5 2 2 1 1 1
and a some related arbitrary bit vector (except that the
last bit must be 0), for example
   b=: ?.2#~#a

Find the smallest indices c such that
   c *./ .> I.b
   c *./ .<:&({&a) I.b

thus, if
   b=:(i.#a) e. 1 2 5 7 12 14
in the above example,
   c=: 2 17 9 8 13 15

Values of b where c can not exist (for example, if the last
bit in b is a 1) should cause an error.

example=:4 :0  NB. a example b
   c=.1+I.y
   while.1 e. s=.c >&({&x) I.y do.
      c=.c+s
   end.
   c
)

   A=: 0,~ ([EMAIL PROTECTED])(-<./)+/\<:?.1e3#3
   B=: 0,~?.2#~<:#A
   (6!:2,7!:2) 'A example B'
0.306458 149824

Can you do better than this?

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to