Use a lookup table encoded in floating-point numbers
A slightly advanced tip:
Small lookup tables are useful for code golf: it's very often that we need a function that maps, for example, 0 to 1, 1 to 2, 2 to 1, and everything else to 0. However, TI-BASIC arrays are not suited for this purpose: for one thing, they're one-based, and for another, a value cannot be extracted until the array is stored in Ans
or a list variable.
In my answer here, I store a small lookup table in a magic constant in base 11. Simply list the values you want to use,
{0,-1,5,-1,-1,2,9,-1,8,6}
convert to a useful form
{1,0,6,0,0,3,10,0,9,7}
write in your desired base (base 11)
.106003A097
and convert to base 10
-1+int(11fPart(11^Ans.0954191904
The shortest array approach is 8 bytes longer!
{1,0,6,0,0,3,10,0,9,7}-1:Ans(X+1
TI-BASIC only stores floats to 14 decimal digits, so you can store up to 44ish bits but only 14 decimal digits.
This technique can often be improved further by using brute-force search to find a magic constant rather than base-N encoding. I'm still in the process of golfing the answer above, but the lengendary TI-BASIC golfer Weregoose used this method to generate the differences between numbers coprime with 30 (that is, a repeating list of 6, 4, 2, 4, 2, 4, 6, 2
) on the wiki/forum TI-BASIC Developer with this snippet:
2+2iPart(3fPart(576e^(fPart(I/8
The magic constant 576 was found using Mathematica, but if you don't own a copy use a script in your favorite language.
6Please always include which version you are refering to! – flawr – 2015-06-24T11:39:05.030