_iPhoenix_ suggested I should make a thread where I dump some random TI-Basic knowledge. There are definitely some users out there that are more knowledgeable so I encourage them to throw in some quirks that I don't mention. Obviously this'll just be a mashup of random things that come to mind in no particular order. I might add some in the future.
  1. On color calcs, using the color tokens (BLUE, RED, BLACK, etc.) is 0.07ms faster than just digits (10,11,12, etc.).
  2. When performing multiplications, it is considerably faster to have the largest number (in terms of digits) on the left.
  3. System variables (finance vars, window vars, recursive n, etc. ) are 0.5ms faster than the OS variables (A, B, C, D, etc.) Ans isn't as fast as system variables, but it can be faster than storing to a variable depending on context. On the TI-83 series, the difference is even bigger (1.3ms)
  4. The smallest way to generate a list of numbers 1...n is cumSum(binomcdf(n-1,0. However, if you already have a list L1 of dimension n, you can do cumSum(1 or L1, and if you don't care about the order, you can do randIntNoRep(1,n,n
  5. The smallest way to chop off the first element of a list in Ans is ΔList(cumSum(Ans
  6. The smallest way to chop off the last element of a list in Ans is ΔList(cumSum(Ans)-Ans
  7. The logic operator "and" is lower than "or" and "xor" in the order of operations , so something like 1 xor 1 and 0 evaluates to true.
  8. En is faster than 10^n, so when possible, you should use it.
  9. ~int(~Ans is ceil()
  10. Vertical text sprites are generally faster than horizontal text sprites. Also, for horizontal text sprites, there is no token that will produce 01011 as its left-most pixels, but there are tokens for all 31 other combinations.
  11. sum() can be used to get the nth element of a list inline by setting the 2nd and 3rd arguments to n (eg. sum({1,2,3},3,3 returns the 3). Speaking of which, both sum() and prod() have seldom-used optional 2nd and 3rd arguments which specify start and end positions.
  12. toString() is quite a bit faster than eval()
  13. GetCalc(A:e(A=π)+π(A≠π→A will set A to π on one calculator and e on the other, allowing for two connected calculators to run the same program in a turn-based fashion. (from tibasicdev)
  14. I don't think this is intentional but in the DCSE8 SDK, there is a command that isn't documented which is DrawInt(), it is used to draw a colored int with a transparent background to the active GRAM buffer. It is used as follows: real(6,9,X,Y,[color code],[expr]
  15. int(logBASE(16,2 is 3 Laughing
  16. You can do factorials of halves like 2.5! but not other decimal numbers.
  17. I don't think a lot of people know that you can seed the random number generator like this: [seed]→rand. Also 196164532 is the seed to generate 1 so 196164532→rand:rand will return 1 (technically it will return 0.99999999999889 but the calculator will display it as 1. The rand routine cannot actually return 1 but it can get real close)
  18. For() loops don't check for an overflow when incrementing, so you can go beyond 10^100 like this
  19. An unclosed parenthesis at the end of a For() line is considerably slower if the following line is either an If without a Then:End, or an IS>( or DS<( statement and the condition is false.
  20. Using the built-in list variables L1-L6 is faster than using custom ones like ʟA
  21. This one isn't particularly obscure, but you don't need a newline at the end of a DelVar command, so you can save a byte by doing something like DelVar AIf A=0...
  22. If the very last line of a program is value-returning, the value will be displayed on the homescreen. There will also be no "Done" if you do this.
  23. There is an undocumented optional first argument for the Text() command which, if set to -1, will display the text on the graph screen in the home screen font.
  24. On color calcs, using Line() with linestyle 1 (1px thick) is almost twice as fast as linestyle 2.

Some of these come from me, others I learnt around the internet over the years, sorry if I can't give proper credit.
This is great! Long, long ago, The BASIC Elite made a guide called The 1337 Guide to TI-BASIC that 15 years ago, I'm still proud of, but I (and the community) have definitely learned way, way more in that intervening decade and a half. Please do share your (collective) tips and tricks here, and depending on people's willingness for those tips to go further, I'd potentially be interested in updating the 1337 Guide.
I have one.

You can store 4 values in 1 variable, or list or matrix element by doing:

Code:
value1+value2/|E3+value3[i]+value4[i]/|E3->N

Where |E is the mathematical operator and [i] represents the imaginary i. E3 should be increased if your values are more than 3 digits long.

This results in a number like 1.002+3.004i

You can get the individual values back like this:

Code:
value1 = real(iPart(N
value2 = real(|E3fPart(N
value3 = imag(iPart(N
value4 = imag(|E3fPart(N
Michael2_3B wrote:
I have one.

You can store 4 values in 1 variable, or list or matrix element by doing:

Code:
value1+value2/|E3+value3[i]+value4[i]/|E3->N

Where |E is the mathematical operator and [i] represents the imaginary i. E3 should be increased if your values are more than 3 digits long.

This results in a number like 1.002+3.004i

You can get the individual values back like this:

Code:
value1 = real(iPart(N
value2 = real(|E3fPart(N
value3 = imag(iPart(N
value4 = imag(|E3fPart(N

I wouldn't be surprised if this could be expanded to 5-6 values specifically on the 83PCE.

Besides that, I felt really dumb after reading mr womp womp's post, thinking I had pretty much mastered TI-BASIC over the years. There's always more to learn I guess. Razz
After seeding 42→rand, int(9rand(8 gives eight unique values with evens on the left, odds on the right.

One not-so-outlandish application is in menuing (see the careful reordering of label arguments):


Code:
42→rand
Menu("","ALICE",7,"BOBBY",1,"CAROL",5,"DAVID",2,"ELISA",4,"FRANK",3,"GRACE",6
Lbl 1:rand
Lbl 2:rand
Lbl 3:rand
Lbl 4:rand
Lbl 5:rand
Lbl 6:rand
Lbl 7
Disp sub("ALICEBOBBYCAROLDAVIDELISAFRANKGRACE",5int(9rand)-9,5)+" IS COOL!


This saves a handful of bytes over using Ans+1 each label prior to dictionary lookup you may have seen me use before.

Code:
mod1  = 2147483563
mod2  = 2147483399
mult1 = 40014
mult2 = 40692
seed1 = 12345
seed2 = 67890

def seed(n):
  global seed1, seed2, mod1, mod2
  if(n<0):
    n = -n
  if(n==0):
    seed1 = 12345
    seed2 = 67890
  else:
    seed1 = (mult1*n)%mod1
    seed2 = n%mod2

def rand():
  global seed1, seed2, mod1, mod2, mult1, mult2
  result = 0
  seed1 = (seed1*mult1)%mod1
  seed2  = (seed2*mult2)%mod2
  result = (seed1-seed2)/mod1
  if(result<0):
    result = result+1
  return round(result,5)

def randInt(min, max):
  return min + int((max-min+1)*rand())


Here's a python snippet that implements TI's BASIC rand routines, useful for brute-forcing seeds and such. Be warned that I don't use TI's float format for these so your mileage as far as precision goes may vary- almost certainly good enough for randInt though.

Edit: I should note that it is a Combined linear congruential generator and the constants are on the wiki article too, because they're desirable for various reasons Smile
On a TI−84 Plus, if you end a program with "Stop", then run program−related commands like "Pause " or "Menu()" (on the home screen) will run as if a program was running until you see a normal error message.

On a Ti−84 Plus CE, due to a bug in a memory address (talking about hex code), binompdf() and binomcdf() can cause some glitchy numbers if one of the parameters is greater than 255. Some digits would be replaced by stat plot points or a superscript 3.
Source: https://www.cemetech.net/forum/viewtopic.php?t=17286&postdays=0&postorder=asc&start=0
Something simple:
Generally it's good to avoid the use of unnecessary brackets and quotes.
Doing so saves bytes and often even time.
If a closing bracket or quote is the last character of a command line
or the last digit before a "store" sign
you can simply remove it.

Code:
Output(1,1,"A")
to:
Output(1,1,"A

For(A,0,9)
to:
For(A,0,9

L1(1)→A
to:
L1(1→A

"ABC"→Str1
to:
"ABC→Str1

Well, I assume most of you are familiar with these "tricks".
Also this is a good idea:

Code:
If (A=1)(B=2
to:
If (A=1 and B=2

Sometimes a closing bracket can be dispensed
by thinking through the expression before a "store" sign:

Code:
L1(1)+A→L1(1
to:
A+L1(1→L1(1
1st (more optimization then info):
When doing getkey donít do (k is the key you are pressing)

Code:
If k=25
X+1→X
End

Do

Code:
X+(K=25→X

Pretty much if you are holding the right arrow key (key 25) it will add 1

2nd: never use X or Y as variables (lots of pain from doing that)

A 3rd: if you run out of strings in your program or want to store the strings somewhere else so they wonít get corrupted, store them into a list and take it out when you need it. A would be 1, B would be 2, C would be 3 and so on. There are programs on the archives for this but they are pretty easy to make yourself Smile


Sorry for editing so much I keep wanting to change things Razz
It's hard to quantify what this thread is for, but it's definitely not for routines and such- those belong here: https://www.cemetech.net/forum/viewtopic.php?t=1642

Code:
mod1  = 2147483563
mod2  = 2147483399
mult1 = 40014
mult2 = 40692
seed1 = 12345
seed2 = 67890

def seed(n):
  global seed1, seed2, mod1, mod2
  if n < 0:
    n = -n
  if n == 0:
    seed1 = 12345
    seed2 = 67890
  else:
    seed1 = (mult1*n)%mod1
    seed2 = n%mod2

def rand():
  global seed1, seed2, mod1, mod2, mult1, mult2
  result = 0
  seed1 = (seed1 * mult1) % mod1
  seed2  = (seed2 * mult2) % mod2
  result = (seed1 - seed2) / mod1
  if result < 0:
    result = result+1
  return round(result,5)

def randInt(min, max, count=None):
  if count == None:
    return min + int((max-min+1)*rand())
  else:
    result = [randInt(min, max) for _ in range(count)]
    return result

def randIntNoRep(min, max, count=None):
  if count == None:
    result = list(range(min, max+1))
    count = len(result)
    for i in range(count, 0, -1):
      j = randInt(0, count-1)
      result[i-1], result[j] = result[j], result[i-1]
    return result
  else:
    result = []

    inc = False
    failures = 0
    while len(result) < count:
      num = randInt(min, max)

      if num in result:
        failures += 1
        if failures == 3:
          inc = !inc
          while num in result:
            if inc:
              num += 1
              if num > max:
                num = min
            else:
              num -= 1
              if num < min:
                num = max
          failures = 0
          result.append(num)
      else:
        failures = 0
        result.append(num)
   
    return result


I added randIntNoRep with the assistance of jacobly and some additional help from Zeda, Zeroko, and Logical. You can mess around with it on Google Colab.
Fun fact:

69! is the largest integer factorial you can do on the calculator, before having an overflow error.
Of course it is. It just had to be that number. (If anyone asks you what 69 is, tell them it looks the same when rotated 180 degrees.)
  
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.

» Go to Registration page
Page 1 of 1
» 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

 

Advertisement