-
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.
lessons: add two new list opt lessons
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
lessons/list-optimizations/0004-list-optimizations-find-a-pattern-easy.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,35 @@ | ||
# Find a Pattern (easy) | ||
List constants often have patterns. Ask "what do the elements of this list have in common?" or "can I express this as a sequence?". | ||
|
||
_Hint: Remember that the color constants are just numbers. What operations can you do on lists of numbers?_ | ||
|
||
```json | ||
{ | ||
"id": 4, | ||
"name": "List Optimizations: Find a Pattern (easy)", | ||
"requirements": [3], | ||
"starting_program": "{RED,ORANGE,YELLOW,GREEN,BLUE,MAGENTA->L1\n{0,3,24,81,192,375,648,1029->L2", | ||
"required_savings": 20, | ||
"tests": [ | ||
{ | ||
"regex": "10\\+{1,5,9,4,0,3->L1[\\n:]seq\\(3([A-Z]|theta)\\^\\^3,\\1,0,7->L2" | ||
}, | ||
{ | ||
"regex": "seq\\(3([A-Z]|theta)\\^\\^3,\\1,0,7->L2[\\n:]10\\+{1,5,9,4,0,3->L1" | ||
}, | ||
{ | ||
"input": [{"name": "L3", "value": [0,3,24,81,192,375,648,1029]}], | ||
"output": [ | ||
{ | ||
"name": "L1", | ||
"value": [11,15,19,14,10,13] | ||
}, | ||
{ | ||
"name": "L2", | ||
"value": [0,3,24,81,192,375,648,1029] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
42 changes: 42 additions & 0 deletions
42
lessons/list-optimizations/0006-list-optimizations-binompdf.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,42 @@ | ||
# List Optimizations: `binompdf(`and`binomcdf(` | ||
In addition to their expected uses in probability and statistics, the `binompdf(` and `binomcdf(` commands are useful in TI-BASIC when generating certain special lists. | ||
|
||
Critically for optimization, `binompdf(N,0` produces a list with a single one, followed by N zeros. Also, in the two argument case, `binomcdf(` is, definitionally, `cumSum(binompdf(`. | ||
|
||
We can put these two facts together in interesting ways: | ||
- `cumSum(binomcdf(N,0` -> `{1,2,3,4,5,...,N+1` | ||
- `cumSum(not(binompdf(N,0` -> `{0,1,2,3,4,...,N` | ||
|
||
Expressing a sequence using `seq(` often takes more bytes than expressing the sequence using these techniques, especially if the trailing parentheses in the `binom` method can be pruned. | ||
|
||
```json | ||
{ | ||
"id": 6, | ||
"name": "List Optimizations: binompdf( and binomcdf(", | ||
"requirements": [4], | ||
"starting_program": "15seq(X,X,1,10->L1\n{WHITE,LTGRAY,MEDGRAY,GRAY,DARKGRAY->L2", | ||
"required_savings": 7, | ||
"tests": [ | ||
[ | ||
{ | ||
"input": [], | ||
"output": [ | ||
{ | ||
"name": "L1", | ||
"value": [15,30,45,60,75,90,105,120,135,150] | ||
} | ||
] | ||
}, | ||
{ | ||
"input": [], | ||
"output": [ | ||
{ | ||
"name": "L2", | ||
"value": [20,21,22,23,24] | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} | ||
``` |