-
Notifications
You must be signed in to change notification settings - Fork 1
/
Math-Genius.bat
503 lines (443 loc) · 15.1 KB
/
Math-Genius.bat
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
@echo off
Title Math Genius
:reset
endlocal
setlocal EnableDelayedExpansion
set dataAddress=BatchScript_Data\MathGenius\Scores
if not exist "%dataAddress%" md "%dataAddress%"
set "logName=Scores_%username%.log"
set "logsAddress=%dataAddress%\%logName%"
set "questionType1=Add"
set "questionType2=Sub"
set "questionType3=Mul"
set "questionType4=Div"
set "questionType5=Xp2"
set "questionType6=Xp3"
set "questionType7=Rp2"
set "questionType8=Rp3"
set "questionType9=Rgq"
:inQuestionType
set "questionTypeNum=NA"
set "questionType=NA"
cls
echo Choose the type of math question you want to answer
echo 1. Addition
echo 2. Subtraction
echo 3. Multiplication
echo 4. Division
echo 5. Square
echo 6. Cube
echo 7. Square root
echo 8. Cube root
echo 9. Random challenges
echo=
echo 0. Exit
echo=
set /p "questionTypeNum=Type: "
if "%questionTypeNum%" == "0" exit
if %questionTypeNum% geq 1 if %questionTypeNum% leq 9 set "questionType=!questionType%questionTypeNum%!"
if "%questionTypeNum%" == "C" goto clearScore
if "%questionTypeNum%" == "c" goto clearScore
if not %questionType%==NA goto inLevel
echo=
echo Invalid choice
pause
goto inQuestionType
:inLevel
set "questionLevelName=NA"
set "questionLevelNum=NA"
set "questionLevelName1=Very Easy"
set "questionLevelName2=Easy"
set "questionLevelName3=Normal"
set "questionLevelName4=Medium"
set "questionLevelName5=Hard"
set "questionLevelName6=Expert"
set "questionLevelName7=Extreme"
cls
echo Choose the difficulty level
for /l %%n in (1,1,9) do if defined questionLevelName%%n echo %%n. !questionLevelName%%n!
echo 0. Back
echo=
set /p "questionLevelNum=Level: "
set "questionLevelName=!questionLevelName%questionLevelNum%!"
if %questionLevelNum%==0 goto inQuestionType
if not "%questionLevelName%"=="NA" goto inQuestionNum
echo=
echo Invalid Choice
pause
goto inLevel
:inQuestionNum
set totalQnum=0
cls
set/p "totalQnum=Set the number of %questionLevelName% question = "
if %totalQnum% leq 0 goto ivQnum
if %totalQnum% geq 10000 goto ivQnum
if %totalQnum% geq 500 goto pQnum
goto start
:pQnum
echo=
choice /c YN /m "Are you sure you want %totalQnum% questions? "
if %errorlevel%==1 goto start
goto inQuestionNum
:ivQnum
cls
echo Invalid number
pause
goto inQuestionNum
:start
cls
set "timeStart=%time%"
set "correctAns=0"
set "wrongAns=0"
set "questionNum=0"
set "questionRandom=false"
set "mathOP=3.3"
if "%questionType%"=="Rgq" set "questionRandom=true"
:genQuestion
set /a questionNum=%questionNum%+1
set iAns=x
title Math Genius - [%questionType%:%questionLevelName%] [Q#%questionNum%/%totalQnum%]
set rnGen=0
set rnNum=2
if %questionRandom% == true set /a questionTypeNum=7 * %random% / 32767 + 1
if %questionRandom% == true if %questionLevelNum% leq 4 set /a questionTypeNum=3 * %random% / 32767 + 1
set "questionType=!questionType%questionTypeNum%!"
:rnGenType
set /a rnGen=%rnGen%+1
for %%n in (5 6 7 8) do if "%questionTypeNum%"=="%%n" set rnNum=1
set "rnMin=1" & set "rnMax=30"
set rn=%random%
rem Additions
if "%questionTypeNum%"=="1" (
set "mathOP=1"
if "%questionLevelNum%"=="1" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=15"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=15"
)
if "%questionLevelNum%"=="2" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=49"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=49"
)
if "%questionLevelNum%"=="3" (
if "%rnGen%"=="1" set "rnMin=10" & set "rnMax=100"
if "%rnGen%"=="2" set "rnMin=10" & set "rnMax=100"
)
if "%questionLevelNum%"=="4" (
if "%rnGen%"=="1" set "rnMin=10" & set "rnMax=1000"
if "%rnGen%"=="2" set "rnMin=10" & set "rnMax=1000"
)
if "%questionLevelNum%"=="5" (
if "%rnGen%"=="1" set "rnMin=1000" & set "rnMax=10000"
if "%rnGen%"=="2" set "rnMin=1000" & set "rnMax=10000"
)
if "%questionLevelNum%"=="6" (
if "%rnGen%"=="1" set "rnMin=10000" & set "rnMax=1000000"
if "%rnGen%"=="2" set "rnMin=10000" & set "rnMax=1000000"
)
if "%questionLevelNum%"=="7" (
if "%rnGen%"=="1" set "rnMin=1000000" & set "rnMax=1000000000"
if "%rnGen%"=="2" set "rnMin=1000000" & set "rnMax=1000000000"
)
goto rnCheckVarLimit
)
rem Subtractions
if "%questionTypeNum%"=="2" (
set "mathOP=1"
if "%questionLevelNum%"=="1" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=15"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=15"
)
if "%questionLevelNum%"=="2" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=49"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=49"
)
if "%questionLevelNum%"=="3" (
if "%rnGen%"=="1" set "rnMin=10" & set "rnMax=100"
if "%rnGen%"=="2" set "rnMin=10" & set "rnMax=100"
)
if "%questionLevelNum%"=="4" (
if "%rnGen%"=="1" set "rnMin=10" & set "rnMax=1000"
if "%rnGen%"=="2" set "rnMin=10" & set "rnMax=1000"
)
if "%questionLevelNum%"=="5" (
if "%rnGen%"=="1" set "rnMin=1000" & set "rnMax=10000"
if "%rnGen%"=="2" set "rnMin=1000" & set "rnMax=10000"
)
if "%questionLevelNum%"=="6" (
if "%rnGen%"=="1" set "rnMin=10000" & set "rnMax=1000000"
if "%rnGen%"=="2" set "rnMin=10000" & set "rnMax=1000000"
)
if "%questionLevelNum%"=="7" (
if "%rnGen%"=="1" set "rnMin=1000000" & set "rnMax=1000000000"
if "%rnGen%"=="2" set "rnMin=1000000" & set "rnMax=1000000000"
)
goto rnCheckVarLimit
)
rem Multiplications
if "%questionTypeNum%"=="3" (
set "mathOP=2"
if "%questionLevelNum%"=="1" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=10"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=10"
)
if "%questionLevelNum%"=="2" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=25"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=10"
)
if "%questionLevelNum%"=="3" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=100"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=50"
)
if "%questionLevelNum%"=="4" (
if "%rnGen%"=="1" set "rnMin=10" & set "rnMax=100"
if "%rnGen%"=="2" set "rnMin=10" & set "rnMax=100"
)
if "%questionLevelNum%"=="5" (
if "%rnGen%"=="1" set "rnMin=100" & set "rnMax=1000"
if "%rnGen%"=="2" set "rnMin=100" & set "rnMax=1000"
)
if "%questionLevelNum%"=="6" (
if "%rnGen%"=="1" set "rnMin=1000" & set "rnMax=10000"
if "%rnGen%"=="2" set "rnMin=1000" & set "rnMax=10000"
)
if "%questionLevelNum%"=="7" (
if "%rnGen%"=="1" set "rnMin=1000" & set "rnMax=46340"
if "%rnGen%"=="2" set "rnMin=1000" & set "rnMax=46340"
)
goto rnCheckVarLimit
)
rem Divisions
if "%questionTypeNum%"=="4" (
set "mathOP=2"
if "%questionLevelNum%"=="1" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=10"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=10"
)
if "%questionLevelNum%"=="2" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=25"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=25"
)
if "%questionLevelNum%"=="3" (
if "%rnGen%"=="1" set "rnMin=1" & set "rnMax=50"
if "%rnGen%"=="2" set "rnMin=1" & set "rnMax=50"
)
if "%questionLevelNum%"=="4" (
if "%rnGen%"=="1" set "rnMin=10" & set "rnMax=100"
if "%rnGen%"=="2" set "rnMin=10" & set "rnMax=100"
)
if "%questionLevelNum%"=="5" (
if "%rnGen%"=="1" set "rnMin=100" & set "rnMax=1000"
if "%rnGen%"=="2" set "rnMin=100" & set "rnMax=1000"
)
if "%questionLevelNum%"=="6" (
if "%rnGen%"=="1" set "rnMin=1000" & set "rnMax=10000"
if "%rnGen%"=="2" set "rnMin=100" & set "rnMax=1000"
)
if "%questionLevelNum%"=="7" (
if "%rnGen%"=="1" set "rnMin=1000" & set "rnMax=46340"
if "%rnGen%"=="2" set "rnMin=1000" & set "rnMax=46340"
)
goto rnCheckVarLimit
)
rem Square
if "%questionTypeNum%"=="5" (
set "mathOP=3.2"
if "%questionLevelNum%"=="1" set "rnMin=1" & set "rnMax=10"
if "%questionLevelNum%"=="2" set "rnMin=1" & set "rnMax=15"
if "%questionLevelNum%"=="3" set "rnMin=1" & set "rnMax=20"
if "%questionLevelNum%"=="4" set "rnMin=10" & set "rnMax=30"
if "%questionLevelNum%"=="5" set "rnMin=10" & set "rnMax=50"
if "%questionLevelNum%"=="6" set "rnMin=25" & set "rnMax=125"
if "%questionLevelNum%"=="7" set "rnMin=100" & set "rnMax=625"
goto rnCheckVarLimit
)
rem Cube
if "%questionTypeNum%"=="6" (
set "mathOP=3.3"
if "%questionLevelNum%"=="1" set "rnMin=1" & set "rnMax=10"
if "%questionLevelNum%"=="2" set "rnMin=1" & set "rnMax=15"
if "%questionLevelNum%"=="3" set "rnMin=5" & set "rnMax=20"
if "%questionLevelNum%"=="4" set "rnMin=10" & set "rnMax=25"
if "%questionLevelNum%"=="5" set "rnMin=15" & set "rnMax=40"
if "%questionLevelNum%"=="6" set "rnMin=25" & set "rnMax=100"
if "%questionLevelNum%"=="7" set "rnMin=75" & set "rnMax=500"
goto rnCheckVarLimit
)
rem Square root
if "%questionTypeNum%"=="7" (
set "mathOP=3.2"
if "%questionLevelNum%"=="1" set "rnMin=1" & set "rnMax=10"
if "%questionLevelNum%"=="2" set "rnMin=1" & set "rnMax=15"
if "%questionLevelNum%"=="3" set "rnMin=1" & set "rnMax=20"
if "%questionLevelNum%"=="4" set "rnMin=10" & set "rnMax=30"
if "%questionLevelNum%"=="5" set "rnMin=10" & set "rnMax=50"
if "%questionLevelNum%"=="6" set "rnMin=25" & set "rnMax=125"
if "%questionLevelNum%"=="7" set "rnMin=100" & set "rnMax=625"
goto rnCheckVarLimit
)
rem Cube root
if "%questionTypeNum%"=="8" (
set "mathOP=3.3"
if "%questionLevelNum%"=="1" set "rnMin=1" & set "rnMax=10"
if "%questionLevelNum%"=="2" set "rnMin=1" & set "rnMax=15"
if "%questionLevelNum%"=="3" set "rnMin=5" & set "rnMax=20"
if "%questionLevelNum%"=="4" set "rnMin=10" & set "rnMax=25"
if "%questionLevelNum%"=="5" set "rnMin=15" & set "rnMax=40"
if "%questionLevelNum%"=="6" set "rnMin=25" & set "rnMax=100"
if "%questionLevelNum%"=="7" set "rnMin=75" & set "rnMax=500"
goto rnCheckVarLimit
)
:rnCheckVarLimit
set "varTest1=0"
if "%mathOP%"=="1" set /a varTest1=%rnMax% * 2
if "%mathOP%"=="2" set /a varTest1=%rnMax% * %rnMax%
if "%mathOP%"=="3.2" set /a varTest1=%rnMax% * %rnMax%
if "%mathOP%"=="3.3" set /a varTest1=%rnMax% * %rnMax% * %rnMax%
if %varTest1% geq 0 if %varTest1% leq 2147483647 goto randomizer
title Math Genius - [%questionType%:%questionLevelName%(X)] [Q#%questionNum%/%totalQnum%]
:randomizer
set /a rnRange=%rnMax%-%rnMin%+1
set /a rnRange2=%rnRange%/32767
set /a rnRange1=%rnRange% %% 32767 + 1
set /a rn=%random%*%rnRange2% + (%rnRange1%*%random%/32768) + %rnMin%
if "%rnGen%"=="1" set rn1=%rn%
if "%rnGen%"=="2" set rn2=%rn%
if not %rnGen%==%rnNum% goto rnGenType
goto question%questionType%
:questionAdd
set /a ans=%rn1% + %rn2%
set/p "ians=%rn1% + %rn2% = "
goto ansCheck
:questionSub
set ans=%rn1%
set /a rn1=%ans% + %rn2%
set/p "ians=%rn1% - %rn2% = "
goto ansCheck
:questionMul
set /a ans=%rn1% * %rn2%
set/p "ians=%rn1% * %rn2% = "
goto ansCheck
:questionDiv
set /a ans=%rn1%
set /a rn1=%ans% * %rn2%
set/p "ians=%rn1% / %rn2% = "
goto ansCheck
:questionXp2
set /a ans=%rn1% * %rn1%
set/p "ians=%rn1% ^ 2 = "
goto ansCheck
:questionXp3
if "%questionLevelNum%"=="4" if %random% leq 16383 set "rn1=-%rn1%"
if "%questionLevelNum%"=="5" if %random% leq 16383 set "rn1=-%rn1%"
set /a ans=%rn1%*%rn1%*%rn1%
set/p "ians=%rn1% ^ 3 = "
goto ansCheck
:questionRp2
set "ans=%rn1%"
set /a rn1=%rn1%*%rn1%
set/p "ians=%rn1% ^ (1/2) = "
goto ansCheck
:questionRp3
if "%questionLevelNum%"=="4" if %random% leq 16383 set "rn1=-%rn1%"
if "%questionLevelNum%"=="5" if %random% leq 16383 set "rn1=-%rn1%"
set ans=%rn1%
set /a rn1=%rn1%*%rn1%*%rn1%
set/p "ians=%rn1%^(1/3) = "
goto ansCheck
:ansCheck
if %ians% == #exit goto reset
if %ans% == %ians% goto ansCorrect
goto ansWrong
:ansCorrect
set/a correctAns=%correctAns%+1
echo Correct^^!
goto doneGenQuestion
:ansWrong
set/a wrongAns=%wrongAns%+1
echo Wrong^^! Ans: %ans%
goto doneGenQuestion
:doneGenQuestion
echo=
if %questionNum% == %totalQnum% goto finish
goto genQuestion
:finish
set timeEnd=%time%
call :difftime timeDiff %timeStart% %timeEnd%
call :ftime timeDiff %timeDiff%
echo You have done all the questions
echo Press any key to see your score and statistics
pause > nul
if "%questionType%"=="add" set "questionTypeName=Addition"
if "%questionType%"=="sub" set "questionTypeName=Subtraction"
if "%questionType%"=="mul" set "questionTypeName=Multiplication"
if "%questionType%"=="div" set "questionTypeName=Division"
if "%questionType%"=="xp2" set "questionTypeName=Square"
if "%questionType%"=="xp3" set "questionTypeName=Cube"
if "%questionType%"=="rp2" set "questionTypeName=Square root"
if "%questionType%"=="rp3" set "questionTypeName=Cube root"
if "%questionRandom%"=="true" set "questionTypeName=Random Question"
set /a score= %correctAns% * 100 / %totalQnum%
@echo User : %username% >> %logsAddress%
@echo Date : %date% >> %logsAddress%
@echo Questions type : %questionTypeName% >> %logsAddress%
@echo Difficulty : %questionLevelName% >> %logsAddress%
@echo Time taken : %timeDiff% >> %logsAddress%
@echo Correct answers : %correctAns% >> %logsAddress%
@echo Total questions : %totalQnum% >> %logsAddress%
@echo Score : %score% >> %logsAddress%
echo ======================================= >> %logsAddress%
@echo= >> %logsAddress%
title Math Genius
cls
echo =============== Results ===============
echo=
echo Questions type : %questionTypeName%
echo Difficulty : %questionLevelName%
echo Time taken : %timeDiff%
echo Correct answers : %correctAns%
echo Total questions : %totalQnum%
echo Your score : %score%
echo=
echo Saved to "%logsAddress%"
pause
goto pPlayAgain
:clearScore
echo=
choice /c YN /m "Are you sure you want to delete your scores?"
if %errorlevel% == 2 goto inQuestionType
del %logsAddress%
echo=
echo Your scores have been deleted.
pause
goto inQuestionType
:pPlayAgain
cls
title Math Genius
choice /c YN /m "Do you want to do another set of question? "
if %errorlevel%==1 goto reset
exit
rem Functions
:difftime return_var end_time [start_time] [--no-fix]
set "%~1=0"
for %%t in (%~2:00:00:00:00 %~3:00:00:00:00) do for /f "tokens=1-4 delims=:." %%a in ("%%t") do (
set /a "%~1+=24%%a %% 24 *360000 +1%%b*6000 +1%%c*100 +1%%d -610100"
set /a "%~1*=-1"
)
if /i not "%4" == "--no-fix" if "!%~1:~0,1!" == "-" set /a "%~1+=8640000"
exit /b 0
:ftime return_var centiseconds
set "%~1="
setlocal EnableDelayedExpansion
set "_result="
set /a "_remainder=(%~2) %% 8640000"
for %%s in (360000 6000 100 1) do (
set /a "_digits=!_remainder! / %%s + 100"
set /a "_remainder%%= %%s"
set "_result=!_result!!_digits:~-2,2!:"
)
set "_result=!_result:~0,-4!.!_result:~-3,2!"
for /f "tokens=*" %%r in ("!_result!") do (
endlocal
set "%~1=%%r"
)
exit /b 0