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

{$variable}

Calculator Compatibility

TI-83/84/+/SE/CSE/CE

Author

RogueBantha, kg583

//Finds first occurrence of X in L₁
1+sum(not(cumSum(L₁=X

//Finds last occurrence of X in L₁
max((L₁=X)cumSum(1 or L₁

// Finds the Nth occurrence of X in L₁
1+sum(not(max(0,1-N+cumSum(L₁=X
or
1+sum(not(min(0,N-1-cumSum(L₁=X

Given a value in X, this code will search L₁ and return the index number of the desired occurrence of X.

Error Conditions

If L₁ does not contain X, the first and third routines will both return 1+dim(L₁); the second will return zero.

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 License.