三角形を生成する非常に人気のあるプログラム (名前は忘れました) があります。このプログラムでは、両側に質問または回答があり、各三角形は 1 つの三角形の回答が別の三角形の質問と一致するように適合し、正しく組み合わせると一致します。より大きな形状 (通常は正六角形) を作成します。
$t
カードを含む 2D 配列であるスクリプトを作成しようとしています。
$t = array();
// $t['1'] represents the 'center' triangle in this basic example
$t['1'] = array(
'1', // One side of T1, which is an answer
'3-1', // Another side, this is a question
'2+1' // Final side, another question
);
// These cards go around the outside of the center card
$t['2'] = array(
'2-1' // This is a question on one side of T2, the other sides are blank
);
$t['3'] = array(
'2' // This is an answer on one side of T3, the other sides are blank
);
$t['4'] = array(
'3' // This is an answer on one side of T4, the other sides are blank
);
ここで行う必要があるのは、たとえば、「T1-S1 は T2 と一致し、T1-S2 は T3 と一致し、T1-S3 は T4 と一致する」ということです。私は試しましたが、これまでのところ以下のとおりです。
foreach ($t as $array) {
foreach ($array as $row) {
$i = 0;
while ($i <= 4) {
if(in_array($row, $t[$i])){
echo $row . ' matches with triangle ' . $i . '<br />';
}
$i++;
}
}
}
注: 上記のコードは、すべての質問が「解決」された単純化されたバージョン用であり、2 つの側面を一致させるだけでした。
コードを実行すると、次の出力が得られます。
1 matches with triangle 1
1 matches with triangle 2
2 matches with triangle 1
2 matches with triangle 3
3 matches with triangle 1
3 matches with triangle 4
1 matches with triangle 1
1 matches with triangle 2
2 matches with triangle 1
2 matches with triangle 3
3 matches with triangle 1
3 matches with triangle 4
問題は、$row
実際の三角形ではなく、三角形の側面のみを教えてくれることです。だから私の質問はこれです:
「Ta-Sb は Tc-Sd と一致する」を出力するようにスクリプトを機能させるにはどうすればよいですか。a は三角形、b は辺、c は一致する三角形、d は一致する辺です。 、各配列で辺の値が順番に並んでいると仮定しますか?
質問が明確であることを願っていますが、ご不明な点がございましたらお気軽にお問い合わせください。
また、理想的には、一度一致すると、一致しTa-Sb with Tc-Sd
ないはずTc-Sd with Ta-Sb
です。それも可能ですか?