>
> At first glance the verb  calcIdx   is unobtainable, as the stepwise index
> is lost; the argument grows as a function of its previous states (i.e. it is
> a recurrence relation), so we cannot use the length of the argument.  But
Ok, the verb I posted is a so called self expanding but controlled generator

I started with the recurrence relation:
rabS=:(([:$:_1+]),[:$:_2+])^:(1<])M.

And here's a decimal form using Fibonacci OLEIS A005203:

rabD=: ]`(([:$:_2+])+[:($:*2&[EMAIL PROTECTED])_1+])@.(1<]) M.
  or
rabD1=: (([:$:_2+])+[:($:*2&[EMAIL PROTECTED])_1+])^:(1<]) M.
(n.b. fib from jwiki Essays/Fibonacci sequences)

      rabD"0 i.10
0 1 2 5 22 181 5814 1488565 12194330294 25573364166211253

And Fibonacci is everywhere

   fib"0 i.13
0 1 1 2 3 5 8 13 21 34 55 89 144

   [EMAIL PROTECTED]"0 i.13
1 1 2 3 5 8 13 21 34 55 89 144 233

Number of one's in sequence:
now=:+/@rabS

Number of zero's:
noz=:[:+/[EMAIL PROTECTED]


   noz"0 [1+i.13
0 1 1 2 3 5 8 13 21 34 55 89 144
   now"0 [1+i.13
1 1 2 3 5 8 13 21 34 55 89 144 233

> then, it occured to me that one and only one  1  , is added at every step. 
> So the definition of  calcIdx  is simply  +/  .  Therefore we obtain:
>
>          zUr6 =: $:&1 0 : ((, 1 , 0 #~ 1 = ({~ +/))@:]^:[)
What can I say!
>
> Now, I personally find forms like  u@:]^:[  unappealing.  Usually I try to
> convert them into the equivalent  x u&n y   form.  This is especially true
> when I also see a bound argument.  In this case, the argument isn't bound,
> but it is defaulted.  And losing the monad would also clean up the
> parenthesis mess a bit.  But I leave the reforumlation as an exercise for
> the reader.
I'll give it a try  :-)

Thanks Dan

=@@i
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to