Is there a way to detect if a certain number is in a custom list? PT_ gave me this code, but it returns: ERROR: INCREMENT


Code:

:2→A
:max(seq(X(A=LCAT(X)),X,1,dim(LCAT
:If Ans=0
:Return
:If Ans=5
:Disp "Hi


I am cecking if the value 2 exists in List CAT. I think the code is for checking premade lists, not custom ones.

A screenshot by PT_:
http://imgur.com/70Rk6eW
I believe that PT_ got the code from the TI-Basic Code Fragments and Routines page. I find it to be quite useful as well. However, the given code finds where a value occurs in a list. From what you posted, you just want to see if a value exists anywhere in the list. This can be done by:
Code:
max(2=LCAT
But what does that return or, would I use it in an If statement?
the error is only possible if the dimension of your list is 0
can you show me you list?
It was {2} on the homescreen.

http://imgur.com/f8QKqyu[/img]
So it returns 0 if the number doesn't exist an d it returnes the value of A if it does exist?
no, if it exists, my first code return the index, where that number is found in the list, or it will return 0, if not exists. in the code of Electromagnet8, it will return or 1 or 0, if it exists in that list or not
Actually, when you do a comparison in TI-BASIC, it returns a Boolean value of 0 (false) or 1 (true). In TI-BASIC, comparing a number to a list will create a list of these Boolean values, applying the comparison to each element of the list. So 2={1,2,3,4,3,2,1} would perform the comparisons {2=1,2=2,2=3,2=4,2=3,2=2,2=1} = {0,1,0,0,0,1,0}. max( will return the maximum value of a list, or two numbers, so max(2,1) returns 2, while max({1,3,2}) returns 3.

Since the list of Boolean values are only 0 or 1, if they are all 0, max() will return 0 which means none of them were 2. If it returns 1, it means that at least one of the values was true (equal to 2).

So max(2=LCAT will return 0 if there are no matches, and 1 if there is a match.
Thank you for explaining that, I needed to understand what the expression returned and how it worked.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement