Urgent ..... The problem of digital recombination calculation
This post was last edited by STARYJK on 2013-05-15 12:58:27
Problem Description:
Now there is a set of numbers that need to calculate the total number of reorganizations and calculate the total at the fastest speed.
The numbers are not necessarily the given, they may be other numbers
Digital:
Example One
1->0123
2->01234
3->678
Total: 60
Example Two
1->0123456789
2->0123456789
3->01234
Total: 500
Write a method to calculate the total number of the reorganization and the number after reorganization
Share to:
------Solution--------------------
What does that 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
[Ten] + 037
[One] = 038
[046]
[+] = 047
[+] = 048
[106]
[+] = 107
[+] = 108
[+] = 116
[+] = 117
[118]
[+] = 126
[+] = 127
[+] = 128
[+] = 136
[+] = 137
[+] = 138
[+] = 146
[147]
[+] = 148
[206]
[+] = 207
[+] = 208
[+] = 216
[+] = 217
[+] = 218
[+] = 226
[PNS] = 227
[228]
[236]
[+] = 237
[+] = 238
[+] = 246
[+] = 247