File tree Expand file tree Collapse file tree 3 files changed +20
-20
lines changed Expand file tree Collapse file tree 3 files changed +20
-20
lines changed Original file line number Diff line number Diff line change 11<?php
22
3- function getRules ()
3+ function getRules (): string
44{
55 return 'What is the result of the expression? ' ;
66}
77
8- function generateQuestion ()
8+ function generateQuestion (): string
99{
10- $ firstOperand = rand (1 , 20 );
11- $ secondOperand = rand (1 , 20 );
10+ $ firstOperand = random_int (1 , 20 );
11+ $ secondOperand = random_int (1 , 20 );
1212 $ actions = ["+ " , "- " , "* " ];
13- $ operation = $ actions [rand (0 , 2 )];
13+ $ operation = $ actions [random_int (0 , 2 )];
1414 return "$ firstOperand $ operation $ secondOperand " ;
1515}
1616
17- function getCorrectAnswer ($ question )
17+ function getCorrectAnswer ($ question ): int
1818{
1919 list ($ firstOperand , $ operation , $ secondOperand ) = explode (" " , $ question );
20+ $ firstOperand = (int )$ firstOperand ;
21+ $ secondOperand = (int )$ secondOperand ;
2022 switch ($ operation ) {
2123 case "+ " :
2224 return $ firstOperand + $ secondOperand ;
Original file line number Diff line number Diff line change 11<?php
22
3- function getRules ()
3+ function getRules (): string
44{
55 return 'Answer "yes" if the number is even, otherwise answer "no". ' ;
66}
77
8- function generateQuestion ()
8+ function generateQuestion (): int
99{
10- return rand (1 , 20 );
10+ return random_int (1 , 20 );
1111}
1212
13- function getCorrectAnswer ($ question )
13+ function getCorrectAnswer ($ question ): string
1414{
1515 return $ question % 2 ? 'no ' : 'yes ' ;
1616}
Original file line number Diff line number Diff line change 11<?php
22
3- function getRules ()
3+ function getRules (): string
44{
55 return 'Find the greatest common divisor of given numbers. ' ;
66}
77
8- function generateQuestion ()
8+ function generateQuestion (): string
99{
1010 if (rand (1 , 3 ) === 1 ) {
11- // 33% случаев - гарантированный нетривиальный НОД
12- $ base = rand (2 , 25 );
13- $ firstNumber = $ base * rand (2 , 10 );
14- $ secondNumber = $ base * rand (2 , 10 );
11+ $ base = random_int (2 , 25 );
12+ $ firstNumber = $ base * random_int (2 , 10 );
13+ $ secondNumber = $ base * random_int (2 , 10 );
1514 } else {
16- // 67% случаев - полностью случайные
17- $ firstNumber = rand (1 , 100 );
18- $ secondNumber = rand (1 , 100 );
15+ $ firstNumber = random_int (1 , 100 );
16+ $ secondNumber = random_int (1 , 100 );
1917 }
2018 return "$ firstNumber $ secondNumber " ;
2119}
2220
23- function getCorrectAnswer ($ question )
21+ function getCorrectAnswer ($ question ): int
2422{
2523 list ($ secondNumber , $ firstNumber ) = explode (" " , $ question );
2624
You can’t perform that action at this time.
0 commit comments