diff --git a/composer.json b/composer.json index 140b7bd..8f0d80e 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ } ], "require": { - "wp-cli/php-cli-tools": "^0.11.19", - "ext-gmp": "*" + "wp-cli/php-cli-tools": "^0.11.19" }, "bin": [ "bin/brain-games", diff --git a/src/Games/GcdGame.php b/src/Games/GcdGame.php index c9f276e..feb5f18 100644 --- a/src/Games/GcdGame.php +++ b/src/Games/GcdGame.php @@ -10,11 +10,14 @@ return function ($module) { $module[LOCATION_SETTINGS][SETTING_RULES] = 'Find the greatest common divisor of given numbers.'; - $module[LOCATION_HANDLERS][HANDLER_QUESTION] = function () { + $gcd = function ($a, $b) use (&$gcd) { + return $b === 0 ? $a : $gcd($b, $a % $b); + }; + + $module[LOCATION_HANDLERS][HANDLER_QUESTION] = function () use ($gcd) { $firstNum = random_int(1, 100); $secondNum = random_int(1, 100); - - $expectedAnswer = gmp_gcd($firstNum, $firstNum); + $expectedAnswer = $gcd($firstNum, $firstNum); $question = "$firstNum $secondNum"; return [$question, $expectedAnswer]; };