TI-BASIC:Index Finder
Routine Summary
Returns the index number of an element searched for within a list
Inputs
X - Element that it's finding L₁ - List that's being searched
Outputs
Ans - Index number of element searched.
Variables Used
Variables not documented.
Calculator Compatibility
TI-83/84/+/SE/CSE Author
RogueBantha Download
No download provided.
//Finds first occurence of X in L1 1+sum(not(cumSum(L1=X))) //Finds last occurence of X in L1 max((L1=X)cumSum(1 or L1))
Given a value in X, this code will search L1 and return the index number of the first (or last) occurrence of X. For example, in a list L1={1,2,5,4}, the index value of the element 5 is 3. Storing 5 to X and running this code will return 3.
Error Conditions
The first routine returns 1+Dim(L₁) if L1 does not contain X, so if L1={1,2,5,4} and one searches for 9, the code will return 5.
The second routine returns 0 if L1 does not contain X, so L1={1,2,5,4} and one searches for 9, the code will return 0.