What is the smallest or fastest way to return the index of a list, where the number is ~2, starting from the index of A?
So
Code:
```A=2, L1 = {~1,7,~2,1,~1,6,~2} would return 3```
and
Code:
```A=5, L1 = {~1,7,~2,1,~1,6,~2} would return 7```
You can use this to find the index, where N is the number to search for, and A is the starting index:

Code:
``` A+sum(not(cumSum(N=seq(L1(X),X,A,dim(L1 ```

If you are going to run this many times, replace X with [recursiven].
Here is a routine without seq( to return the first instance of N starting from A. Since it computes the entire list, it will be slower when A is close to dim(L1 and both are large.

Code:
``` cumSum(1 or L1 min(Ans+ᴇ9(Ans<A or N≠L1 ```

Thanks to jonbush for fixing
lirtosiast wrote:
Here is a routine without seq( to return the first instance of N starting from A. Since it computes the entire list, it will be slower when A is close to dim(L1 and both are large.

Code:
``` cumSum(1 or L1 min(E9(Ans<A)+Ans*(N=L1 ```

This is almost correct. The code below should work properly:

Code:
``` cumSum(1 or L1 min(E9(Ans<A or N!=L1)+Ans ```

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.

»
» 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