Urgent ..... number reorganization calculation problem This post was last edited by staryjk in 2013-05-1512: 58: 27 problem description: now there is a set of numbers to calculate the total number after reorganization, calculate the total number with the fastest speed. numbers are not necessarily given, or may be other numbers: Example 1-& gt; 01232-& gt; 012343-& gt; 678 total: 60 example 2 1-& urgent ..... digital restructuring computing problems
This post was last edited by staryjk at 12:58:27
Problem description:
Now there is a set of numbers that need to calculate the total number after reorganization, and calculate the total number with the fastest speed.
Numbers are not necessarily given, but may be other numbers.
Number:
Example 1
1-> 0123
2-> 01234
3-> 678
Total: 60
Example 2
1-> 0123456789
2-> 0123456789
3-> 01234
Total: 500
Write a method to calculate the total number after reorganization and the number after reorganization.
Share To: 01232-> 012343-> 678 Total: 60... 'data-pics = ''>
------ Solution --------------------
What does this mean?
$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] = & gt; 106
[16] = & gt; 107
[17] => 108.
[18] = & gt; 116
[19] = & gt; 117
[20] = & gt; 118
[21] = & gt; 126
[22] = & gt; 127
[23] = & gt; 128
[24] = & gt; 136
[25] = & gt; 137
[26] = & gt; 138
[27] = & gt; 146
[28] = & gt; 147
[29] = & gt; 148
[30] => 206.
[31] = & gt; 207
[32] = & gt; 208
[33] = & gt; 216
[34] = & gt; 217
[35] = & gt; 218
[36] = & gt; 226
[37] = & gt; 227
[38] = & gt; 228
[39] = & gt; 236
[40] = & gt; 237
[41] = & gt; 238
[42] = & gt; 246
[43] = & gt; 247