Help us understand the problem. What is going on with this article?

# プログラマ脳を鍛える数学パズル Q.02「数列の四則演算」

• 1.for文で1000~9999を回す。
• 2.正規表現指定（0を全て除外）
• 3.数字を各位（千、百、十、一）に分け、それぞれの間に四則演算を入れたfor文。
• 4.文字列式を作成。
• 5.結合文字列をevalで計算 +6.対象数字と反転した結合結果の数字が一致するなら出力
```<?php
\$four_calc = array('+', '-', '*', '/','');
\$count = count(\$four_calc);
for (\$num = 1000; \$num < 10000; \$num++) {
if (preg_match("/[0]+/", \$num)) {
continue;
}
\$arrNum = str_split(\$num);
for (\$i = 0; \$i < \$count; \$i++) {
for (\$j = 0; \$j < \$count; \$j++) {
for (\$k = 0; \$k < \$count; \$k++) {
\$cal_form = \$arrNum[0].\$four_calc[\$i].
\$arrNum[1].\$four_calc[\$j].
\$arrNum[2].\$four_calc[\$k].
\$arrNum[3]; // 文字列式を作成
if (mb_strlen(\$cal_form) >= 5) {
if (eval("return {\$cal_form};") == strrev(\$num)) {
print \$cal_form . "=" . \$num . "\n";
}
}
}
}
}
}
?>
```

34歳元医療コンサル営業→名古屋でプログラマー（Ruby）
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away