-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath.rpl
183 lines (157 loc) · 5.23 KB
/
Math.rpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
'Math'
<<
@ Define custom menu to offer way to exit or start different drill.
{{ "Menu" }{ }{ }{ }{ }{ "Quit" }} TMENU
CLLCD
@ If the stack is empty, display the title screen, otherwise go
@ to the choose menu. This is used by the Menu button later.
IF DEPTH 0 == THEN " Math" 3 DISP .5 WAIT
" FLASH" 4 DISP .5 WAIT
" Cards" 5 DISP 1 WAIT
END
@ Select which match drill to start.
{ Addition Subtract Multiply Division }
DUP
"Select one..."
SWAP
1 CHOOSE
@ If Quit option was selected in Choose menu, exit.
IF 0 == THEN
CLEAR
0 MENU
KILL
END
@ Locate position of choosen string in list.
@ Initialize variables...
@ m = menu (1=Add, 2=Sub, 3=Mult, 4=Div)
@ k = keypress code
POS 0 -> m k
<<
CLLCD 3 FREEZE
" Press any key" 4 DISP
" to start." 5 DISP
-1 WAIT 'k' STO
@ Process button from custom menu, if pressed.
CASE k 11.1 == THEN @ Menu button was pressed.
1 Math
END
k 16.1 == THEN @ Quit button was pressed.
CLEAR
2.01 MENU
KILL
END
END
CLLCD
1 12 for i { 1 2 3 4 5 6 7 8 9 10 11 12 }
-> x
@ x = list of terms to be randomized.
<<
@ ------------------------------------------------------
@ Fisher-Yates Shuffle routine.
@ Update seed of pseudo random generator from CLK.
0 RDZ
@ For every list member, starting with the last element,
@ pick a random position from 1 to, but not equal to the
@ current element, and swap values. Repeat for each list
@ index, down to 1.
@ for i = (n - 1) to 1, where n = size of list.
x SIZE 1 - 1 FOR i
i 1 +
i RAND * 1 + FLOOR -> j k
<<
@ Swap the list elements at index j and k.
x j GET @ Get value from index j in list.
x k GET @ Get value from index k in list.
x j ROT PUT @ Put value from index k to index j.
k ROT PUT @ Put value from index j to index k.
'x' STO @ Update list in memory.
>>
-1 STEP
@ ------------------------------------------------------
1 12 FOR j
@ Get random number from list i, position j.
i x j GET
@ If Addition or Multiplication, swap term order.
IF j 2 MOD m 1 == m 3 == OR AND
THEN
SWAP
END
@ Initalize variables.
@ a + b = (a + b) for addition.
@ (a + b) - a = b for subtraction.
@ a * b = (a * b) for multiplication.
@ (a * b) / a = b for division.
@ eq = string equation
@ ans = equation answer
@ t = 0.1 sec timer
0 0 0 -> a b eq ans t
<<
@ Reset number format to standard.
STD
CASE
m 1 == THEN
@ Create the addition equation.
a " + " + b + 'eq' STO
@ Store the answer.
a b + 'ans' STO
END
m 2 == THEN
@ Create the subtraction equation.
a b + " - " + a + 'eq' STO
@ Store the answer.
b 'ans' STO
END
m 3 == THEN
@ Create the multiplication equation.
a " x " + b + 'eq' STO
@ Store the answer.
a b * 'ans' STO
END
m 4 == THEN
@ Create the division equation.
a b * " / " + a + 'eq' STO
@ Store the answer.
b 'ans' STO
END
END
@ Display the equation to solve.
CLLCD
" " eq + " = ?" + 4 DISP
DO
@ Update the time counter.
.1 't' STO+
.1 WAIT
@ Exit loop once a key is pressed.
UNTIL KEY END CLEAR
@ Wait for 1/2 sec to display the answer.
.5 WAIT
" " eq + " = " ans + 4 DISP
@ Display feedback based on time to answer.
CASE
t 1 <= THEN " Amazing!" END
t 2 <= THEN " Pretty good." END
t 4 <= THEN " Good." END
" Ok."
END
7 DISP
@ Wait for a keypress, and save it.
-1 WAIT 'k' STO
@ Process button from custom menu, if pressed.
CASE
k 11.1 == THEN @ Menu button was pressed.
1 Math
END
k 16.1 == THEN @ Quit button was pressed.
@ Clear stack and custom menu, and exit.
CLEAR
2.01 MENU
KILL
END
END
>>
NEXT
>>
NEXT
>>
CLEAR 0 MENU
>>