ljapkin-roman/php-project-lvl1

View on GitHub
src/Games/gcd.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
namespace Ogurchik\Games\gcd;
use function Ogurchik\Engine\engine;

const DESCRIPTION = 'Find the greatest common divisor of given number';

function getGcd($first, $second)
{
        return $first % $second ? getGcd($second, $first % $second) : $second;
}

function launch()
{
    $generateData = function () {
            $first = rand(1, 200);
            $second = rand(1, 200);
            $data['correctAnswer'] = (string)getGcd($first, $second);
            $data['question'] = "$first $second";
            return $data;
    };
    engine(DESCRIPTION, $generateData);
}