-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Closing Delimiter Optimizations | ||
Closing parentheses, brackets, braces, and quotes are optional in three situations: | ||
- At the end of a line | ||
- Before a store arrow | ||
- At the end of a string that will be evaluated as an expression (eg. `expr(`, attached list formula, equation variable) | ||
|
||
Closing delimiter optimizations are among the most plentiful optimizations in regular programs. Occasionally, you will have to manipulate an expression to maximize the savings. | ||
|
||
```json | ||
{ | ||
"id": 1, | ||
"name": "Closing Delimiters", | ||
"requirements": [0], | ||
"starting_program": "sum(L1)/5->A\nIf L1(2)<A or B\nDisp A", | ||
"required_savings": 2, | ||
"tests": [ | ||
{ | ||
"regex": "\\.2sum\\(L1\\->A[\\n:]If B or A>L1\\(2[\\n:]Disp A" | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Intro to One- and Two-Byte Tokens | ||
Even though this course has you type TI-BASIC code character-by-character on your computer, it is essential to remember that TI-BASIC is instead constructed out of *tokens*, with each token requiring either one or two bytes. Expert TI-BASIC programmers can scan a line of code and sum up exactly how many bytes that line costs. In the words of legendary golfer lirtosiast, you should "know the sizes of the most common tokens so you can golf in your head while cooking, taking a shower, etc." | ||
|
||
TI managed to fit __243__ tokens in one byte. In my experience, it is far easier to memorize these one-byte tokens than to attempt to remember all of the two-byte tokens; there are strong patterns in the one-byte tokens that aid memorization. | ||
|
||
Most of the tokens relating to numbers are one byte. However, there is a notable and common exception; identify and remove it from the expression. | ||
|
||
_Hint: The expression will not have valid language syntax after you remove this token._ | ||
|
||
```json | ||
{ | ||
"id": 2, | ||
"name": "Intro to One- and Two-Byte Tokens", | ||
"requirements": [0], | ||
"starting_program": "[|e]^pi[i]=~1", | ||
"required_savings": 2, | ||
"tests": [ | ||
{ | ||
"regex": "\\^pi\\[i\\]=~1" | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Intro to List Optimization | ||
Lists are a strength of TI-BASIC. The language supports many different ways of creating and manipulating lists and it is often possible to create, manipulate, and reduce a list all on one line. | ||
|
||
We'll start this section by exploring different ways to create lists. Begin by creating a list of 9 zeros. | ||
|
||
```json | ||
{ | ||
"id": 3, | ||
"name": "Intro to List Optimization", | ||
"brief_description": "Create a list with 9 zeros.", | ||
"requirements": [1], | ||
"starting_program": "{0,0,0,0,0,0,0,0,0}", | ||
"required_savings": 15, | ||
"tests": [ | ||
{ | ||
"regex": "0rand\\(9" | ||
}, | ||
{ | ||
"input": [], | ||
"output": [ | ||
{ | ||
"name": "Ans", | ||
"value": [0,0,0,0,0,0,0,0,0] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
18 changes: 18 additions & 0 deletions
18
lessons/one-and-two-byte-tokens/0005-string-and-list-names.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# One- and Two-Byte Tokens: String, Matrix, and List Names | ||
|
||
It's easy to forget that built-in list, string, and matrix names are two bytes. There's an optimization to use these names as little as possible; can you spot it? | ||
|
||
```json | ||
{ | ||
"id": 5, | ||
"name": "String, Matrix, and List Names (One- and Two-Byte Tokens)", | ||
"requirements": [2], | ||
"starting_program": "sum(L1->A\nLine(L1(1),L1(2),L1(3),L1(4", | ||
"required_savings": 2, | ||
"tests": [ | ||
{ | ||
"regex": "L1[\\n:]Line\\(Ans\\(1\\),Ans\\(2\\),Ans\\(3\\),Ans\\(4[\\n:]sum\\(Ans->A" | ||
} | ||
] | ||
} | ||
``` |