http://learn.cemetech.net/index.php?title=TI-BASIC:Optimize_Ans&feed=atom&action=historyTI-BASIC:Optimize Ans - Revision history2024-03-29T06:29:22ZRevision history for this page on the wikiMediaWiki 1.34.0http://learn.cemetech.net/index.php?title=TI-BASIC:Optimize_Ans&diff=1149&oldid=prevMaintenance script: Initial automated import2016-02-24T18:37:13Z<p>Initial automated import</p>
<p><b>New page</b></p><div>The [[TI-BASIC:Ans|Ans]] variable (last answer) is a temporary variable that can hold any variable. Ans is changed when there is an expression or variable storage or when pausing with the [[TI-BASIC:Pause|Pause]] command. It is mostly useful when you are just manipulating one variable. To use Ans just put an expression on a line by itself; it will automatically be stored to Ans. You can then change the expressions on the next line where the variable was called and put Ans there instead.<br />
<br />
:getKey→A<br />
:B+(A=26)-(A=24→B<br />
can be<br />
:getKey<br />
:B+(Ans=26)-(Ans=24→B<br />
<br />
If you have more than one line that calls the variable, you should just keep the variable. However, for the first line that calls the variable you should change the variable to Ans.<br />
<br />
:getKey→A<br />
:B+(A=26)-(A=24→B<br />
:C+(A=34)-(A=25→C<br />
can be<br />
:getKey→A<br />
:B+(Ans=26)-(Ans=24→B<br />
:C+(A=34)-(A=25→C<br />
<br />
If you store the same value to two or more variables one after the other, use Ans for each one after the first variable.<br />
<br />
:500→A<br />
:A→B<br />
:A→C<br />
can be<br />
:500→A<br />
:Ans→B<br />
:Ans→C<br />
<br />
When there is a common expression that is on multiple lines, it is sometimes smaller to put the expression on its own line and then change the expression on the other lines to Ans.<br />
<br />
:30+5A→B<br />
:Disp 25A<br />
:Disp 30+5A<br />
can be<br />
:30+5A→B<br />
:Disp 25A<br />
:Disp Ans<br />
<br />
When you use the same text many times in close proximity, you should put that text on its own line and replace it with Ans wherever it occurs.<br />
<br />
<br />
:Disp "Hello<br />
:Disp "Hello<br />
:Disp "Hello<br />
can be<br />
:"Hello<br />
:Disp Ans,Ans,Ans<br />
<br />
<br />
For complex calculations, there are often multiple parts that are the same. You should take out the most common part and put it on its own line. If there are several common parts, you should take out the part that will result in the greatest size reduction. You then replace that part, wherever it occurs, with Ans.<br />
<br />
<br />
:2A/(BC)+(BC)2→A<br />
can be<br />
:BC<br />
:2A/Ans+Ans2→A<br />
<br />
<br />
When dealing with text there are often situations where the same text is repeated multiple times. Rather than writing out the long string of text, it is sometimes possible to rewrite it using Ans. Put the common part of the text on its own line and on the next line concatenate (add together) with Ans however many times is needed to make the string.<br />
<br />
<br />
:" →Str1 //20 spaces<br />
can be<br />
:" //5 spaces<br />
Ans+Ans+Ans+Ans→Str1<br />
<br />
<br />
If you use the [[TI-BASIC:Sub|Sub(]] command to get the appropriate part of some text based on certain conditions, you can sometimes get rid of the sub( command and just use Ans. You would put each piece of text on its own line, and then put the condition before it.<br />
<br />
<br />
:Input sub("GiveTake",1+4(A=1),4)+" candy?",Str1<br />
can be<br />
:"Give<br />
If A=1:"Take<br />
Input Ans+" candy?", Str1<br />
<br />
<br />
With [[TI-BASIC:Repeat|Repeat]] loops, you can sometimes put Ans in the condition instead of the variable. Even if Ans were 0 at the beginning of the loop, the code will work, since a Repeat loop will always cycle once before the condition is checked.<br />
<br />
<br />
:Repeat A<br />
:getKey→A<br />
:End<br />
can be<br />
:Repeat Ans<br />
:getKey→A<br />
:End<br />
<br />
<br />
When the condition in a Repeat loop has a common part that is repeated multiple times, you should put the common part at the end of the loop and replace the common part in the condition with Ans.<br />
<br />
<br />
:Repeat A=2 and B=1 or A=2 and B=3<br />
:getKey<br />
:A+(Ans=26)-(Ans=24→A<br />
:End<br />
can be<br />
:Repeat Ans and B=1 or Ans and B=3<br />
:getKey<br />
:A+(Ans=26)-(Ans=24→A<br />
:A=2<br />
:End<br />
<br />
<br />
Many times in [[TI-BASIC:If|If]]-Then-Else conditionals the same expression or string of text appears in both the true and false parts. You should put this expression or string of text before the If-Then-Else conditional and then replace it in the conditional with Ans.<br />
<br />
<br />
:If B<br />
:Then<br />
:Disp "Hello<br />
:2Bnot(A→C<br />
:Else<br />
:Disp "Hello<br />
:3→D<br />
:End<br />
can be<br />
:"Hello<br />
:If B<br />
:Then<br />
:Disp Ans<br />
:2Bnot(A→C<br />
:Else<br />
:Disp Ans<br />
:3→D<br />
:End<br />
<br />
<br />
When you have two or more strings of text that share a common part, you should take that common part out. You then can replace it with Ans and concatenate Ans to the strings.<br />
<br />
<br />
:Disp "Hello World<br />
:Disp "Goodbye World<br />
can be<br />
:"World<br />
:Disp "Hello "+Ans<br />
:Disp "Goodbye "+Ans<br />
<br />
<br />
When you have two If conditionals that have math opposite conditions and they display text, it is sometimes possible to remove one of the conditionals and use Ans. Take the text from the first condition and put it on its own line. Then put the second conditional and the text on the next line. You then put the display Ans on the last line.<br />
<br />
<br />
:If A≤B<br />
:Disp "Higher<br />
:If A>B<br />
:Disp "Lower<br />
can be<br />
:"High<br />
:If A>B<br />
:"Low<br />
:If A≠B<br />
:Disp Ans+"er[[Category:TI-BASIC]]<br />
[[Category:TIBD]]</div>Maintenance script