diff --git a/lessons/0001-closing-delimiter.md b/lessons/0001-closing-delimiter.md new file mode 100644 index 0000000..d35dd8c --- /dev/null +++ b/lessons/0001-closing-delimiter.md @@ -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[\\n:]If B or A>L1\\(2[\\n:]Disp A" + } + ] +} +``` \ No newline at end of file diff --git a/lessons/0002-one-and-two-byte-tokens.md b/lessons/0002-one-and-two-byte-tokens.md new file mode 100644 index 0000000..6ec66c0 --- /dev/null +++ b/lessons/0002-one-and-two-byte-tokens.md @@ -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" + } + ] +} +``` \ No newline at end of file diff --git a/lessons/0003-list-optimizations.md b/lessons/0003-list-optimizations.md new file mode 100644 index 0000000..3dc40fc --- /dev/null +++ b/lessons/0003-list-optimizations.md @@ -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] + } + ] + } + ] +} +``` \ No newline at end of file diff --git a/lessons/one-and-two-byte-tokens/0005-string-and-list-names.md b/lessons/one-and-two-byte-tokens/0005-string-and-list-names.md new file mode 100644 index 0000000..a71f3c4 --- /dev/null +++ b/lessons/one-and-two-byte-tokens/0005-string-and-list-names.md @@ -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" + } + ] +} +``` \ No newline at end of file