Skip to content

Commit

Permalink
lessons: add two new list opt lessons
Browse files Browse the repository at this point in the history
  • Loading branch information
rpitasky committed Jan 5, 2025
1 parent e3bd47a commit dadde9a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
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 lessons/list-optimizations/0006-list-optimizations-binompdf.md
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]
}
]
}
]
]
}
```

0 comments on commit dadde9a

Please sign in to comment.