Re: deleting list components


[Prev][Next][Index][Thread]

Re: deleting list components



I have noted the message below still around from last August, without (to my
knowledge) ever having been brought to satisfactory closure:

>  Tomas C wrote:
>  >
>  > I have a list with 10 components and I want to delete just the 3rd
>  > and 7th component inside a program
>  >
>  > exp.  20,19,18,17,13,1,6,5,9,7
>  >
>  > The only way I know how to do this is
>  > :20,19,18,17,13,1,6,5,9,7->L1
>  > :L1->L2
>  > :1->b
>  > :For a,1,2
>  > :L1(a)->L2(b)
>  > :1+b->b
>  > :End
>  > :For a,4,6
>  > :L1(a)->L2(b)
>  > :1+b->b
>  > :End
>  > :For a,8,10
>  > :L1(a)->L2(b)
>  > :1+B->B
>  > :END
>  > :L2->L1
>  > :Delvar(L2)
>  >
>  > I believe there has to be a better way.  simply delteing L1(3) for
>  > instance.  If anyone can help with this, please let me know.
>  >
>  > Tomas
>
>  There is no good way to do it.  This is the shortest possible method I
>  found to do it on the TI-83:
>
>  :20,19,18,17,13,1,6,5,9,7->L1
>  :For(A,4,6
>  :L1(A->L1(A-1
>  :End
>  :For(A,8,10
>  :L1(A->L1(A-2
>  :End
>  :8-dim(L1
>  --
>  Bryan Rabeler <brabeler@ticalc.org>

Let me suggest a more general method that applies to the TI-83.
An even slicker implementation of this idea can be made in the TI-92 or -89
environment, with local variables, etc.

Let us suppose that we have a list L1 (the name is really "L-sub-one", of
course). In list L2 appears, in any order, a list of positions in L1 at which
we wish to delete elements. Thus if L1 is a 20-element list and we wish to
delete the third and twelfth elements, we might set up L2 as {12,3}. We will
store the shortened list into the variable L3. In the process, we will create a
working list named #MASK, where the symbol # is used here to represent the
small "L" symbol used on the TI-83 to prefix the name of a list.
What follows is the "guts" of a program, which could be named
CMPRSS, for example. Running this program would create the list L3 from the two
lists L1 and L2 (and also create the list #MASK as a "side effect", of course).

: 1+0*L1 --> #MASK
: For(I,1,dim(L2)) : 0 --> #MASK(L2(I)) : End
: cumSum(#MASK) --> #MASK
: L1 --> L3 : #MASK(dim(#MASK)) --> dim(L3)
: For(I,dim(L1),1,-1) : L1(I) --> L3(#MASK) : End

The advantage here is that we do not need to specify or know in advance what
the contents of the list L2 are -- this list could be generated automatically
by some process, need not be in order (as said), and may even contain
repetitions.

I am in the process of collecting a set of list-oriented algorithms that could
be used in the TI-xx environments. Any suggestions that others may have would
be welcome.

RWW Taylor
National Technical Institute for the Deaf
Rochester Institute of Technology
Rochester NY 14623

>>>> The plural of mongoose begins with p. <<<<