anonymous No title
No License PHP
2019年07月13日
Copy
function make_ary($x){
	$make_index_ary = function($x) use( &$make_index_ary ){
		if($x==1){
			return [1];
		}
		$first_list = array_map(function($x){
			return $x*2;
			},$make_index_ary($x-1));
		$latter_list = array_map(function($x){
			return $x-1;
			},array_reverse($first_list));
		return array_merge($first_list,$latter_list);
	};
	
	$index_ary = $make_index_ary($x);
	$edge_num = pow(2, $x-1);
	$ary = [];
	for($i=0;$i<$edge_num;$i++){
		$ary[$index_ary[$i]]=($i+1)*2;
	}
	ksort($ary);
	return $ary;
}

print_r (make_ary(5) );
//Array ( [1] => 22 [2] => 12 [3] => 28 [4] => 6 [5] => 20 [6] => 14 [7] => 30 [8] => 4 [9] => 24 [10] => 10 [11] => 26 [12] => 8 [13] => 18 [14] => 16 [15] => 32 [16] => 2 )
function make_ary($x){
	$make_index_ary = function($x) use( &$make_index_ary ){
		if($x==1){
			return [1];
		}
		$first_list = array_map(function($x){
			return $x*2;
			},$make_index_ary($x-1));
		$latter_list = array_map(function($x){
			return $x-1;
			},array_reverse($first_list));
		return array_merge($first_list,$latter_list);
	};
	
	$index_ary = $make_index_ary($x);
	$edge_num = pow(2, $x-1);
	$ary = [];
	for($i=0;$i<$edge_num;$i++){
		$ary[$index_ary[$i]]=($i+1)*2;
	}
	ksort($ary);
	return $ary;
}

print_r (make_ary(5) );
//Array ( [1] => 22 [2] => 12 [3] => 28 [4] => 6 [5] => 20 [6] => 14 [7] => 30 [8] => 4 [9] => 24 [10] => 10 [11] => 26 [12] => 8 [13] => 18 [14] => 16 [15] => 32 [16] => 2 )

Output

Run
年末年始は機械学習・深層学習を勉強しませんか?
No one still commented. Please first comment.
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら