当前位置:Gxlcms > PHP教程 > 急数字重组计算有关问题

急数字重组计算有关问题

时间:2021-07-01 10:21:17 帮助过:26人阅读

急.....数字重组计算问题
本帖最后由 staryjk 于 2013-05-15 12:58:27 编辑

问题描述:
现在有一组数字需要计算重组后总数,以最快的速度计算出总数.
数字不一定就是给出的这些,也有可能是其它数字
数字:
例一
1->0123
2->01234
3->678
总数:60


例二
1->0123456789
2->0123456789
3->01234
总数:500


写一个方法计算出重组后的总数和重组后的号码

分享到:


------解决方案--------------------
这个意思?
$ar = array(
'0123',
'01234',
'678',
);

print_r(foo($ar));
function foo(&$ar, $i=0) {
$res = array();
if($i+1 $t = foo($ar, $i+1);
foreach(str_split($ar[$i]) as $v) {
foreach($t as $r) $res[] = $v . $r;
}
}else $res = str_split($ar[$i]);
return $res;
}
Array
(
[0] => 006
[1] => 007
[2] => 008
[3] => 016
[4] => 017
[5] => 018
[6] => 026
[7] => 027
[8] => 028
[9] => 036
[10] => 037
[11] => 038
[12] => 046
[13] => 047
[14] => 048
[15] => 106
[16] => 107
[17] => 108
[18] => 116
[19] => 117
[20] => 118
[21] => 126
[22] => 127
[23] => 128
[24] => 136
[25] => 137
[26] => 138
[27] => 146
[28] => 147
[29] => 148
[30] => 206
[31] => 207
[32] => 208
[33] => 216
[34] => 217
[35] => 218
[36] => 226
[37] => 227
[38] => 228
[39] => 236
[40] => 237
[41] => 238
[42] => 246
[43] => 247

人气教程排行