DAY 15
0

## 15 柏拉圖問題 探討拿取總價值的期望值 II

if(isset(\$_GET['debug'])) \$debug=\$_GET['debug'];
else \$debug=1;//顯示步驟

if(isset(\$_GET['from'])) \$from=\$_GET['from'];
else \$from=0;

if(isset(\$_GET['gap'])) \$gap=\$_GET['gap'];
else \$gap=1;

if(isset(\$_GET['to'])) \$to=\$_GET['to'];
else \$to=100;

if(isset(\$_GET['limit'])) \$limit=\$_GET['limit'];
else \$limit=100;

if(isset(\$_GET['get_from'])) \$get_from=\$_GET['get_from'];
else \$get_from=25;

if(isset(\$_GET['get_gap'])) \$get_gap=\$_GET['get_gap'];
else \$get_gap=1;

if(isset(\$_GET['get_to'])) \$get_to=\$_GET['get_to'];
else \$get_to=35;

if(isset(\$_GET['loop_num'])) \$loop_num=\$_GET['loop_num'];
else \$loop_num=10000;//跑的次數

printf("Date,percent\get,=>");
for(\$a=\$get_from;\$a<=\$get_to;\$a=\$a+\$get_gap){
printf(",\$a");
}
printf("\$n");

for(\$k=\$from;\$k<=\$to;\$k=\$k+\$gap)
{
\$thedate=date("m-d H:i");
\$percent=\$k;
printf("%s,%.0f,=>", \$thedate, \$percent);
\$total_score=0;

for(\$p=\$get_from;\$p<=\$get_to;\$p=\$p+\$get_gap){
\$get=\$p;

if(\$debug>1)
{
echo "From: ", \$from, \$n;
echo "To: ", \$to, \$n;
echo "Limit: ", \$limit, \$n;
echo "Percent: ", \$percent, \$n;
}

for(\$j=0;\$j<\$loop_num;\$j++)
{
\$choice_time=1;
\$max_num=0;
\$choice=0;
\$score=0;
\$percent_get=\$limit*\$get/100;
\$percent_PR=\$percent/100;
\$thisnum=range(1,\$limit,1);//（小,大,差）
shuffle(\$thisnum);//洗牌

for(\$i=0;\$i<\$limit;\$i++)//選擇
{
\$num=\$thisnum[\$i];
if(\$max_num<\$num) \$max_num=\$num;

\$pos=0;
\$num_PR=0;
for(\$m=0;\$m<\$i;\$m++)//決定大小排列
{
if(\$num>\$thisnum[\$m]) \$pos=\$pos+1;
}
if(\$i>\$percent_get)\$num_PR=\$pos/\$i;
if(\$debug>0) echo \$i+1, " ", \$num, " ", \$num_PR, \$n;
if(\$num_PR>\$percent_PR and \$choice_time>0){
\$choice=\$num;
\$choice_time=\$choice_time-1;
}
}
if(\$choice_time>0){
\$choice=\$num;
\$choice_time=\$choice_time-1;
}
\$score=\$choice;
\$total_score=\$total_score+\$score;

if(\$debug>0){
echo "Choice: ", \$choice, \$n;
echo "Max: ", \$max_num, \$n;
echo "choice_time: ", \$choice_time, \$n;
}

}

\$total_score=\$total_score/\$loop_num;
printf(",%.7f", \$total_score);

}

printf("\$n");

}