Removing a single number from a TI-BASIC list takes O(N)
time where N
is the size of the list. It's simply not practical. Here is the fastest idiom for removing the X
th element:
seq(L₁(A+(A≥X)),A,1,dim(L₁)-1→L₁
As for the indentation, the TI-BASIC interpreter needs to step through one colon at a time, which is relatively fast but not instantaneous. I expect each extra colon to take a TI-84 series calc about 0.1 ms each time through. If you want to maximize speed, get rid of the indentation.
As for other optimizations:
Rather than using E->dim(L1:Fill(1,L1:cumSum(L1->L1
to generate the list, use
cumSum(binomcdf(E-1,0→L₁
which has the same effect.
You can prescan for numbers not divisible by 2, etc; try this:
augment({2},1+2cumSum(binomcdf(int(.5E),0
to generate only the odd numbers.
As a different approach, you can generate prime numbers by adding to, not removing from, a list:
{2
For(𝑛,3,E,2) ;close parenthesis to fix parser bug; step by 2 to catch odd numbers
If min(fPart(𝑛/L₁
n→L₁(1+dim(L₁
End
L₁
It should be of comparable speed or faster.
As a small tip, use the sequence variable n instead of a loop index. It takes as much as 0.5 secondmilliseconds less to access (depending on how many other variables are in your VAT).