Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: blue_bear_94 on August 29, 2013, 09:27:30 pm

Title: How to filter elements in a list?
Post by: blue_bear_94 on August 29, 2013, 09:27:30 pm
Suppose I have a list, say named R. I want every element less than 100 in R to appear in another list.

Even better, I have another named Q, and I'll need 2 lists, so that the elements in one list matches with the other.

For example:
R = {40, 230, 9, 102, 154, 308, 1}
Q = {1, 2, 3, 4, 5, 6, 7}
should give:
{40, 9, 1}
and
{1, 3, 7}
Title: Re: How to filter elements in a list?
Post by: Builderboy on August 29, 2013, 11:21:15 pm
What kind of problems are you having developing an algorithm yourself?  Also depending on the application you are using it for, there might be some additional tricks that you could use if the restrictions were changed slightly.
Title: Re: How to filter elements in a list?
Post by: blue_bear_94 on August 29, 2013, 11:35:55 pm
I'd like a fast way to do this. I can actually think of this:
For(B,1,dim(LR
LR(B
If Ans<E2
Then
Ans->LA(1+dim(LA
LQ(B->LB(1+dim(LB
End

I was wondering who could formulate a faster way.
Title: Re: How to filter elements in a list?
Post by: Builderboy on August 30, 2013, 02:18:54 am
Hmm I can think of a couple different ways to *almost* do the same thing, but not quite :/