Skip to content

Commit dadde9a

Browse files
committed
lessons: add two new list opt lessons
1 parent e3bd47a commit dadde9a

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Find a Pattern (easy)
2+
List constants often have patterns. Ask "what do the elements of this list have in common?" or "can I express this as a sequence?".
3+
4+
_Hint: Remember that the color constants are just numbers. What operations can you do on lists of numbers?_
5+
6+
```json
7+
{
8+
"id": 4,
9+
"name": "List Optimizations: Find a Pattern (easy)",
10+
"requirements": [3],
11+
"starting_program": "{RED,ORANGE,YELLOW,GREEN,BLUE,MAGENTA->L1\n{0,3,24,81,192,375,648,1029->L2",
12+
"required_savings": 20,
13+
"tests": [
14+
{
15+
"regex": "10\\+{1,5,9,4,0,3->L1[\\n:]seq\\(3([A-Z]|theta)\\^\\^3,\\1,0,7->L2"
16+
},
17+
{
18+
"regex": "seq\\(3([A-Z]|theta)\\^\\^3,\\1,0,7->L2[\\n:]10\\+{1,5,9,4,0,3->L1"
19+
},
20+
{
21+
"input": [{"name": "L3", "value": [0,3,24,81,192,375,648,1029]}],
22+
"output": [
23+
{
24+
"name": "L1",
25+
"value": [11,15,19,14,10,13]
26+
},
27+
{
28+
"name": "L2",
29+
"value": [0,3,24,81,192,375,648,1029]
30+
}
31+
]
32+
}
33+
]
34+
}
35+
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# List Optimizations: `binompdf(`and`binomcdf(`
2+
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.
3+
4+
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(`.
5+
6+
We can put these two facts together in interesting ways:
7+
- `cumSum(binomcdf(N,0` -> `{1,2,3,4,5,...,N+1`
8+
- `cumSum(not(binompdf(N,0` -> `{0,1,2,3,4,...,N`
9+
10+
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.
11+
12+
```json
13+
{
14+
"id": 6,
15+
"name": "List Optimizations: binompdf( and binomcdf(",
16+
"requirements": [4],
17+
"starting_program": "15seq(X,X,1,10->L1\n{WHITE,LTGRAY,MEDGRAY,GRAY,DARKGRAY->L2",
18+
"required_savings": 7,
19+
"tests": [
20+
[
21+
{
22+
"input": [],
23+
"output": [
24+
{
25+
"name": "L1",
26+
"value": [15,30,45,60,75,90,105,120,135,150]
27+
}
28+
]
29+
},
30+
{
31+
"input": [],
32+
"output": [
33+
{
34+
"name": "L2",
35+
"value": [20,21,22,23,24]
36+
}
37+
]
38+
}
39+
]
40+
]
41+
}
42+
```

0 commit comments

Comments
 (0)