-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
142 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
<?php | ||
|
||
namespace BrainGames\Games\EvenGame; | ||
namespace BrainGames\Games\CalcGame; | ||
|
||
use RuntimeException; | ||
|
||
use const BrainGames\Utils\ModuleUtils\HANDLER_QUESTION; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_HANDLERS; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_SETTINGS; | ||
use const BrainGames\Utils\ModuleUtils\SETTING_RULES; | ||
|
||
return function ($module) { | ||
$module[LOCATION_SETTINGS][SETTING_RULES] = 'What is the result of the expression?'; | ||
|
||
$module[LOCATION_HANDLERS][HANDLER_QUESTION] = function () { | ||
$operands = ['*', '+', '-']; | ||
$firstNum = random_int(1, 100); | ||
$secondNum = random_int(1, 100); | ||
$operand = $operands[random_int(0, count($operands) - 1)]; | ||
switch ($operand) { | ||
case '*': | ||
$expectedAnswer = $firstNum * $secondNum; | ||
break; | ||
case '+': | ||
$expectedAnswer = $firstNum + $secondNum; | ||
break; | ||
case '-': | ||
$expectedAnswer = $firstNum - $secondNum; | ||
break; | ||
} | ||
function loader($module): array | ||
{ | ||
$module[SETTING_RULES] = 'What is the result of the expression?'; | ||
$module[HANDLER_QUESTION] = static fn() => handler(); | ||
return $module; | ||
} | ||
|
||
$question = "$firstNum $operand $secondNum"; | ||
return [$question, $expectedAnswer]; | ||
}; | ||
function handler(): array | ||
{ | ||
$operators = ['*', '+', '-']; | ||
$firstNum = random_int(1, 10); | ||
$secondNum = random_int(1, 10); | ||
$operator = $operators[random_int(0, count($operators) - 1)]; | ||
switch ($operator) { | ||
case '*': | ||
$expectedAnswer = $firstNum * $secondNum; | ||
break; | ||
case '+': | ||
$expectedAnswer = $firstNum + $secondNum; | ||
break; | ||
case '-': | ||
$expectedAnswer = $firstNum - $secondNum; | ||
break; | ||
default: | ||
throw new RuntimeException('Incorrect operator'); | ||
} | ||
|
||
return $module; | ||
}; | ||
$question = "$firstNum $operator $secondNum"; | ||
return [$question, $expectedAnswer]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
<?php | ||
|
||
namespace BrainGames\Games\EvenGame; | ||
namespace BrainGames\Games\GcdGame; | ||
|
||
use const BrainGames\Utils\ModuleUtils\HANDLER_QUESTION; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_HANDLERS; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_SETTINGS; | ||
use const BrainGames\Utils\ModuleUtils\SETTING_RULES; | ||
|
||
return function ($module) { | ||
$module[LOCATION_SETTINGS][SETTING_RULES] = 'Find the greatest common divisor of given numbers.'; | ||
|
||
$gcd = function ($a, $b) use (&$gcd) { | ||
return $b === 0 ? $a : $gcd($b, $a % $b); | ||
}; | ||
function loader($module): array | ||
{ | ||
$module[SETTING_RULES] = 'Find the greatest common divisor of given numbers.'; | ||
$module[HANDLER_QUESTION] = static fn() => handler(); | ||
return $module; | ||
} | ||
|
||
$module[LOCATION_HANDLERS][HANDLER_QUESTION] = function () use ($gcd) { | ||
$firstNum = random_int(1, 100); | ||
$secondNum = random_int(1, 100); | ||
$expectedAnswer = $gcd($firstNum, $firstNum); | ||
$question = "$firstNum $secondNum"; | ||
return [$question, $expectedAnswer]; | ||
}; | ||
function handler(): array | ||
{ | ||
$firstNum = random_int(1, 10); | ||
$secondNum = random_int(1, 20); | ||
$expectedAnswer = gcd($firstNum, $firstNum); | ||
$question = "$firstNum $secondNum"; | ||
return [$question, $expectedAnswer]; | ||
} | ||
|
||
return $module; | ||
}; | ||
function gcd($a, $b): int | ||
{ | ||
return $b === 0 ? $a : gcd($b, $a % $b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
<?php | ||
|
||
namespace BrainGames\Games\EvenGame; | ||
namespace BrainGames\Games\PrimeGame; | ||
|
||
use const BrainGames\Utils\ModuleUtils\HANDLER_QUESTION; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_HANDLERS; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_SETTINGS; | ||
use const BrainGames\Utils\ModuleUtils\SETTING_RULES; | ||
|
||
return static function ($module) { | ||
$module[LOCATION_SETTINGS][SETTING_RULES] = 'Answer "yes" if given number is prime. Otherwise answer "no".'; | ||
|
||
$module[LOCATION_HANDLERS][HANDLER_QUESTION] = function () { | ||
$isPrime = function ($number) { | ||
if ($number <= 1) { | ||
return false; | ||
} | ||
|
||
for ($i = 2; $i * $i <= $number; $i++) { | ||
if ($number % $i === 0) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
|
||
$question = random_int(1, 100); | ||
$isPrime = $isPrime($question); | ||
return [$question, $isPrime ? 'yes' : 'no']; | ||
}; | ||
|
||
function loader($module): array | ||
{ | ||
$module[SETTING_RULES] = 'Answer "yes" if given number is prime. Otherwise answer "no".'; | ||
$module[HANDLER_QUESTION] = static fn() => handler(); | ||
return $module; | ||
}; | ||
} | ||
|
||
function handler(): array | ||
{ | ||
$question = random_int(1, 15); | ||
$isPrime = isPrime($question); | ||
return [$question, $isPrime ? 'yes' : 'no']; | ||
} | ||
|
||
function isPrime($number): bool | ||
{ | ||
if ($number <= 1) { | ||
return false; | ||
} | ||
|
||
for ($i = 2; $i * $i <= $number; $i++) { | ||
if ($number % $i === 0) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
<?php | ||
|
||
namespace BrainGames\Games\EvenGame; | ||
namespace BrainGames\Games\ProgressionGame; | ||
|
||
use const BrainGames\Utils\ModuleUtils\HANDLER_QUESTION; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_HANDLERS; | ||
use const BrainGames\Utils\ModuleUtils\LOCATION_SETTINGS; | ||
use const BrainGames\Utils\ModuleUtils\SETTING_RULES; | ||
|
||
return function ($module) { | ||
$module[LOCATION_SETTINGS][SETTING_RULES] = 'What number is missing in the progression?'; | ||
|
||
$module[LOCATION_HANDLERS][HANDLER_QUESTION] = function () { | ||
$lengthProgression = 10; | ||
$step = random_int(2, 10); | ||
$shift = random_int(1, 10); | ||
$progression = range($shift, $shift + (($lengthProgression - 1) * $step), $step); | ||
$guessIndex = random_int(0, 8); | ||
$expectedAnswer = $progression[$guessIndex]; | ||
$progression[$guessIndex] = '..'; | ||
$question = implode(' ', $progression); | ||
return [$question, $expectedAnswer]; | ||
}; | ||
|
||
function loader($module): array | ||
{ | ||
$module[SETTING_RULES] = 'What number is missing in the progression?'; | ||
$module[HANDLER_QUESTION] = static fn() => handler(); | ||
return $module; | ||
}; | ||
} | ||
|
||
function handler(): array | ||
{ | ||
$lengthProgression = 10; | ||
$step = random_int(2, 10); | ||
$shift = random_int(1, 10); | ||
$progression = range($shift, $shift + (($lengthProgression - 1) * $step), $step); | ||
$guessIndex = random_int(0, 8); | ||
$expectedAnswer = $progression[$guessIndex]; | ||
$progression[$guessIndex] = '..'; | ||
$question = implode(' ', $progression); | ||
return [$question, $expectedAnswer]; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.