演算子 (加算、減算、乗算、除算)、再グループ化 (運ぶかどうか)、および列 (1 つまたは 2 つ) の 3 つのパラメーターに基づいてランダムな数学的問題を生成する必要があるサイトがあります。私はこれを行う方法について頭を悩ませようとしてきましたが、私が思いついたものには何らかの形で欠陥があります.
これが私が現在取り組んでいるものです:
function create_problem($operator, $regrouping, $columns){
$top = rand(1,9);
$bottom = rand(1,9);
if($operator == "+"){
if($columns == 1 && $regrouping === false){
$result = array(
'top' => $top,
'bottom' => $bottom,
'formula' => "$top.$operator.$bottom"
);
}
if($columns == 2){
if($regrouping === false){
if($top+$bottom > 9){
$diff = ($top+$bottom)-10;
$top = $diff+rand(1, 3);
}
$result = array(
'top' => $top,
'bottom' => $bottom,
'formula' => "$top.$operator.$bottom"
);
}else{
if($top+$bottom < 10){
$top = rand(1, $bottom+1);
}
}
}
}
return $result;
}
誰かがこれに対処した場合、または誰かが指針を持っている場合、私は最も感謝しています!