/** * [is_friendly сумма всех собственных делителей первого числа * равна второму числу и наоборот * @param integer $first первое число * @param integer $second второе число * @return boolean истина/ложь */ function is_friendly($first, $second) { if (array_sum(divisors($first)) == $second && array_sum(divisors($second)) == $first) { return true; } else { return false; } }
function Generate($level) { list($num1, $factors1) = $this->GetNumber($level); $num2 = $num1; while ($num2 == $num1) { list($num2, $factors2) = $this->GetNumber($level); } // // Original exercise // $num1 = 28; // $num2 = 49; // $factors1 = [2,2,7]; // $factors2 = [7,7]; $divisors1 = divisors($num1); $divisors2 = divisors($num2); list($operation, $result) = $this->SetOperation($divisors1, $divisors2, $level); $question = 'Az $A$ halmaz elemei ' . The($num1) . ' $' . $num1 . '$ pozitív osztói, ' . 'a $B$ halmaz elemei ' . The($num2) . ' $' . $num2 . '$ pozitív osztói. ' . 'Adja meg ' . ($operation == 'B\\setminus A' ? 'a' : 'az') . ' $' . $operation . '$ halmazt elemei felsorolásával! <i>(Például: $\\{2;3;4\\}$)</i>'; $correct = $result; $solution = '$' . implode("\$\$;\$\$", $result) . '$'; $hints = $this->Hints($num1, $divisors1, $num2, $divisors2, $result, $operation); // print_r($solution); return array('question' => $question, 'correct' => $correct, 'solution' => $solution, 'hints' => $hints, 'labels' => ['left' => '$\\{$', 'right' => '$\\}$'], 'type' => 'list2'); }