这篇文章已经编辑了一点,如果有任何评论脱离了背景,请原谅。
所以,我正在做gild.com的目标挑战。我的解决方案概念是:
1)确定每个目标选项的价值(定义为:如果被击中,还剩下多少选项)
2)在击打点对数组进行切片
3)掉落任何低于最后一击值的物品
4)重复,直到数组为空
5)返回命中次数
这是我最新的代码。我在共享1&1主机上,所以我不能直接访问错误日志。我有一个变通办法,但它不再写入该文件(所以我猜错误已经改变)。但是当我得到输出时,它总是一个undefined offset
…
UPDATE:现在我一直在玩从各个点回显输出,看看发生了什么,我发现这可以防止正式错误,但它在depth++;
循环后停止回显
<?php
set_time_limit(0);
$targets=array();
$file="http://www.gild.com/coding_test_cases/missile/missile-a.in";
$input=file_get_contents($file);
$input=str_replace("'n'n","'n",$input);
$targets=explode("'n",$input);
if(strlen($targets[count($targets)-1])==0){
array_pop($targets);
}
$rich=array();
$order=array();
while(count($targets)>0){
for($i=0;$i<count($targets);$i++){
$key=$i;
$depth=0;
while($key<count($targets)){
if($targets[$key]>$targets[$i]){
$depth++;
}
$key++;
}
$rich[$i]=$depth;
echo "."; //-----------------------------------I will make it to the screen
}
echo "hi"; //--------------------------------------------------------I will not
$last_strike=$targets[array_pop(array_keys($rich,max($rich)))];
array_push($order,$last_strike);
$targets=array_slice($targets,array_pop(array_keys($rich,max($rich)))+1);
$rich=array();
$c=count($targets);
for($b=0;$b<$c;$b++){
if($targets[$b]<$last_strike){
array_splice($targets,$b,1,true);
$b--;
$c--;
}
}
}
echo count($order)."'n";
?>
也许我错过了一些东西,但你的整个代码片段不等于这个吗?
$rich = range($_GET['lim'] - 1, 0);
echo $rich[0];
至于实际的错误,听起来像是内存分配问题。
我认为你有500错误而不是人类可读错误的原因是关闭了dislay_errors
ini设置。
尝试打开它或在Apache错误日志