Difference between revisions of "TI-BASIC:Index Finder"

From Learn @ Cemetech
Jump to navigationJump to search
(Initial automated import)
 
(Automated @@ correction)
 
Line 1: Line 1:
 
{{Template:TI-BASIC:Routine
 
{{Template:TI-BASIC:Routine
|picture=@@
+
|picture=
 
|summary=Returns the index number of an element searched for within a list
 
|summary=Returns the index number of an element searched for within a list
 
|input=  
 
|input=  
Line 7: Line 7:
 
|output=
 
|output=
 
''Ans'' - Index number of element searched.
 
''Ans'' - Index number of element searched.
|variables=@@
+
|variables=
 
|compatibility=TI-83/84/+/SE/CSE
 
|compatibility=TI-83/84/+/SE/CSE
 
|author=RogueBantha
 
|author=RogueBantha
|authors=@@
+
|authors=
|url=@@
+
|url=
|download=@@
+
|download=
 
}}
 
}}
  

Latest revision as of 17:12, 24 February 2016


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.