If Mikl wants to calculate arbitrary random indices,
here's a though.
Modified Randy's solution
]B=: (| # 0<]) pat
1 1 1 1 0 0 0 1 1 0
The transform has a cycle for each stretch of #B
if input it shifts output by +/B. Each stretch
transforms cycle modulus by
]C=. (-. + _1 + +/\) B
0 1 2 3 4 4 4 4 5 6
Thus,
N=. #B
S=. +/B
tr=. (C {~ N | ]) + S * N <[EMAIL PROTECTED] ]
tr i.20
0 1 2 3 4 4 4 4 5 6 6 7 8 9 10 10 10 10 11 12
tr 1e9+i.8
600000000 600000001 600000002 600000003 600000004 600000004 600000004 600000004
--- Randy MacDonald <[EMAIL PROTECTED]> wrote:
> Hello Mikl;
>
> Sorry, I was thinking that it was pat&foo, but somehow that didn't make it
> to my fingers.
>
> Your illustration of OLD/IXS/NEW clarifies things.
>
> Using the names (pat, OLD):
>
> b =: (#OLD)$(|pat)#pat>0 NB. boolean expansion.
>
> You can get NEW as follows:
>
> NEW =:(1-b)+<:+/\b
>
> BHoJ says there's a simpler solution, it's probably expressible as a tacit
> verb, but this is what came to mind.
>
> You're welcome to try this. Hopefully I made no typos.
> ------------------------------------------------------------------------
> |\/| Randy A MacDonald | APL: If you can say it, it's done.. (ram)
> |/\| [EMAIL PROTECTED] |
> |\ | |If you cannot describe what you are doing
> BSc(Math) UNBF'83 ?as a process, you don't know what you're doing.
> Sapere Aude | - W. E. Deming
> Natural Born APL'er | Demo website: http://156.34.69.76/
> -----------------------------------------------------(INTP)----{ gnat }-
>
> ----- Original Message -----
> From: "Mikl Kurkov" <[EMAIL PROTECTED]>
> To: "Programming forum" <[email protected]>
> Sent: Sunday, June 11, 2006 8:03 PM
> Subject: Re: [Jprogramming] Index converter
>
>
> > > Hello Mikl;
> > >
> > Hello,Randy!
> >
> > > It seems that you're asserting that:
> > >
> > > NEW -: foo OLD
> > >
> > Yes you are right. But more exactly I assert:
> > NEW -: pat foo OLD
> >
> > > I would agree, and can see what foo would be, if
> > >
> > > NEW =: 0 1 2 3 7 8 10 11 12 13 17 18
> > >
> > > but I don't see how you get the NEW you do get.
> > I dont't need values from OLD in result. I need their indexes in your
> > vector. And for removed items I want it to have indexes of next begger
> > value in your vector. It can be calculated from your vector.
> >
> > RNEW =: 0 1 2 3 7 8 10 11 12 13 17 18
> > RIXS =: 0 1 2 3 4 5 6 7 8 9 10 11
> >
> > Now it easy to see how NEW is calculated
> > OLD: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> > IXS: 0 1 2 3 x x x 4 5 x 6 7 8 9 x x x 10 11 x
> > NEW: 0 1 2 3 4 4 4 4 5 6 6 7 8 9 10 10 10 10 11 12
> >
> > But I can't use vector because indexes is values in diapason from 0 to
> > 3e9. So I'm looking for numeral algorithm without making intermediate
> > vectors. In other words I need function that can calculate NEW for 3e9
> > pat foo 3e9 -: ???
> >
> > --
> > Mikl
> >
> > >
> > > Please tell me what my mistake is.
> > >
> > > ------------------------------------------------------------------------
> > > |\/| Randy A MacDonald | APL: If you can say it, it's done.. (ram)
> > > |/\| [EMAIL PROTECTED] |
> > > |\ | |If you cannot describe what you are doing
> > > BSc(Math) UNBF'83 ?as a process, you don't know what you're
> doing.
> > > Sapere Aude | - W. E. Deming
> > > Natural Born APL'er | Demo website: http://156.34.69.76/
> > > -----------------------------------------------------(INTP)----{ gnat }-
> > >
> > > ----- Original Message -----
> > > From: "Mikl Kurkov" <[EMAIL PROTECTED]>
> > > To: <[email protected]>
> > > Sent: Sunday, June 11, 2006 4:21 PM
> > > Subject: [Jprogramming] Index converter
> > >
> > >
> > >> I have task for which I couldn't find a solution.
> > >>
> > >> Suppose we have some indexes which relate to some data.
> > >> Now I have vector which describe which indexes to keep and which to
> > > remove.
> > >>
> > >> For example: pat =: 4 _3 2 _1
> > >>
> > >> Positive value - tell how many indexes to keep, negative to remove. So
> > >> the
> > >> pat is telling that I need to keep 4 first indexes then remove 3 next,
> > >> keep another 2, remove 1, keep 4, remove 3 and so on.
> > >> I need function that for giving index give me new index after applying
> > >> such pattern. Indexes of removed items - is index of next keeped item.
> > >>
> > >> So applying this function to i.20 and pat I should see:
> > >> OLD: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> > >> NEW: 0 1 2 3 4 4 4 4 5 6 6 7 8 9 10 10 10 10 11 12
> > >>
> > >> Another function will make inverse calculation - for each value from
> NEW
> > >> give the biggest value from OLD.
> > >>
> > >> I wonder is it posible to achieve whithout precalculating vector of NEW
> > >> indexes, just by calculating new value from given pat and old index?
> > >>
> > >> Thanks in advance,
> > >> Mikl
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm