$a:
array (size=16)
0 => 文字列 '1' (長さ=1)
1 => 文字列 '3' (長さ=1)
2 => 文字列 '5' (長さ=1)
3 => 文字列「7」(長さ=1)
4 => 文字列 '10' (長さ=2)
5 => 文字列 '12' (長さ=2)
6 => 文字列 '14' (長さ=2)
7 => 文字列 '16' (長さ=2)
8 => 文字列 '17' (長さ=2)
9 => 文字列 '19' (長さ=2)
10 => 文字列 '21' (長さ=2)
11 => 文字列 '23' (長さ=2)
12 => 文字列 '26' (長さ=2)
13 => 文字列 '28' (長さ=2)
14 => 文字列 '30' (長さ=2)
15 => 文字列 '32' (長さ=2)
$b:
配列 (サイズ=16)
0 => 文字列 '2' (長さ=1)
1 => 文字列 '4' (長さ=1)
2 => 文字列 '6' (長さ=1)
3 => 文字列「8」(長さ=1)
4 => 文字列 '9' (長さ=1)
5 => 文字列 '11' (長さ=2)
6 => 文字列 '13' (長さ=2)
7 => 文字列 '15' (長さ=2)
8 => 文字列 '18' (長さ=2)
9 => 文字列 '20' (長さ=2)
10 => 文字列 '22' (長さ=2)
11 => 文字列 '24' (長さ=2)
12 => 文字列 '25' (長さ=2)
13 => 文字列 '27' (長さ=2)
14 => 文字列 '29' (長さ=2)
15 => 文字列 '31' (length=2)
上の数グループ。私は得られる [16, 1, 13, 4] [14, 3, 15, 2] [12, 5, 9, 8] [10,7, 9 、 8]
[32,17,29,20] [30,19,31,18] [28,21,25,24] [26,23,27,22]
/*规律$a = array(1,3,5,7, 10,12,14,16, 17,19,21,23, 26,28,30,32); a1 a2 a3 a4$b = array(2,4,6,8, 9,11,13,15, 18,20,22,24, 25,27,29,31); b1 b2 b3 b4[16, 1,13, 4][14, 3,15, 2][12, 5, 9, 8][10, 7, 9 ,8]a2 + a1 = b2 + b1 = 17[32,17,29,20][30,19,31,18][28,21,25,24][26,23,27,22]a4 + a3 = b4 + b3 = 49*/t(17);t(49);function t($n){ $a = array(1,3,5,7, 10,12,14,16, 17,19,21,23, 26,28,30,32); $b = array(2,4,6,8, 9,11,13,15, 18,20,22,24, 25,27,29,31); $a = array_chunk($a,4); $b = array_chunk($b,4); //15+16 = 31 if($n <= 31){ $useA = array_slice($a,0,2); $useB = array_slice($b,0,2); }else{ $useA = array_slice($a,2,4); $useB = array_slice($b,2,4); } $data = array(); arsort($useA[1]); foreach($useA[1] as $v1){ foreach($useA[0] as $v2){ if($n==$v1+$v2){ $tmp = array(); $tmp[] = $v1; $tmp[] = $v2; $data['a'][] = $tmp; } } } arsort($useB[1]); foreach($useB[1] as $v1){ foreach($useB[0] as $v2){ if($n==$v1+$v2){ $tmp = array(); $tmp[] = $v1; $tmp[] = $v2; $data['b'][] = $tmp; } } } foreach($data['a'] as $k=>$v){ echo join(' , ',array_merge($v,$data['b'][$k])).'<br>'; }}/*16 , 1 , 15 , 214 , 3 , 13 , 412 , 5 , 11 , 610 , 7 , 9 , 832 , 17 , 31 , 1830 , 19 , 29 , 2028 , 21 , 27 , 2226 , 23 , 25 , 24*/
あれ吗?
[ 12, 5, 9, 8 ] 7, 9, 8 ]
怎么解释?
[ 10, 7, 9, 8 ] 应该是[10,7, 11 , 6]
a7 a0 b6 b1
a6 a1 b7 b0 a2 b4 b3
a4 a3 b5 b2
a15 a8 b14 b9
a14 a9 b15 b8
a13 a10 b12 b11
a12 a11 b13 b10
[ 12, 5, 9, 8 ]
[ 10, 7, 9, 8 ]
、就、就就就就他写错了了
他他[30、19、31、31、18]错了?
[ 12, 5, 9, 8 ]
[ 10, 7, 9, 8 ]
他感觉是写错了,不然没规律了
嗯,感觉这样就不是规律了、有限定性
すごい
我想应该这样做
$a = array( 1, 3, 5, 7, 10, 12, 14, 16, 17, 19, 21, 23, 26, 28, 30, 32);$b = array( 2, 4, 6, 8, 9, 11, 13, 15, 18, 20, 22, 24, 25, 27, 29, 31);function foo($a) { $r = array(); foreach(array_chunk($a, 8) as $v) { $t = array_chunk($v, 4); $t = array_map(null, array_reverse($t[1]), $t[0]); $r = array_merge($r, $t); } return $r;}$r = foo($a);foreach(foo($b) as $k=>$v) { $k += $k % 2 ? -1 : 1; $r[$k] = array_merge($r[$k], $v);}print_r($r);
Array( [0] => Array ( [0] => 16 [1] => 1 [2] => 13 [3] => 4 ) [1] => Array ( [0] => 14 [1] => 3 [2] => 15 [3] => 2 ) [2] => Array ( [0] => 12 [1] => 5 [2] => 9 [3] => 8 ) [3] => Array ( [0] => 10 [1] => 7 [2] => 11 [3] => 6 ) [4] => Array ( [0] => 32 [1] => 17 [2] => 29 [3] => 20 ) [5] => Array ( [0] => 30 [1] => 19 [2] => 31 [3] => 18 ) [6] => Array ( [0] => 28 [1] => 21 [2] => 25 [3] => 24 ) [7] => Array ( [0] => 26 [1] => 23 [2] => 27 [3] => 22 ))
确实是调换位置,这个有规律些
[12, 5, 9, 8] [10,7, 9 , 8] 是我写错,不好意思。宗各位所述已经解决谢谢你们。