Last active
June 27, 2018 07:08
-
-
Save webnitros/2b60a9ff76cfff1b15969b929bc5c0b4 to your computer and use it in GitHub Desktop.
Test task Mirafox
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
<?php | |
/** | |
* @param array $c | |
* @return array | |
*/ | |
function averageNumberOfGoals($c) | |
{ | |
$games = $c['games']; | |
$scored = $c['goals']['scored']; | |
$skiped = $c['goals']['skiped']; | |
return array( | |
'scored' => $scored / $games, | |
'skiped' => $skiped / $games | |
); | |
} | |
/** | |
* @param array|null $c1 | |
* @param array|null $c2 | |
* @return array|boolean | |
*/ | |
function match($c1 = null, $c2 = null) | |
{ | |
if (!$c1 or !$c2) return false; | |
// команды 1: cреднее забивание и пропускание голово за все игры | |
$res = averageNumberOfGoals($c1); | |
$c1_scored = $res['scored']; | |
$c1_skiped = $res['skiped']; | |
// команды 2: cреднее забивание и пропускание голово за все игры команды 1 | |
$res = averageNumberOfGoals($c2); | |
$c2_scored = $res['scored']; | |
$c2_skiped = $res['skiped']; | |
$h = $c1_scored * $c2_skiped; | |
$g = $c2_scored * $c1_skiped; | |
$xh = ($h + 1) / ($h + $g); | |
$xg = ($g + 1) / ($h + $g); | |
$c1 = abs(round($h * $xh + 0.2)); | |
$c2 = abs(round($g * $xg - 0.2)); | |
return array($c1, $c2); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment