Page is a not externally linkable
SoulMaster - 12:42 am on Jan 12, 2009 (gmt 0)
for($checkedIndian=$key-2; $indians[$checkedIndian]<$currentIndian ¦¦ $indians[$checkedIndian]>$indians[$checkedIndian+1]; $checkedIndian--) Wont end. I get error: Here's the code: The reason i reversed the array is, that the thing needs to be as fast as possible, there will be a competiton later on, who's code works the fastest.
So basically the array $indians is array full of numbers, wich are ment to be the tallness's of indians standing in a row, and i have to find out wich indian can see most of indians in front of him. He sees the dude standing in front of him for sure, and seeing of the next guy depends on if this next guy is shorter than the indian who looks him or longer than the dude who he stands in front of.
Okay i know it's messy, but look the code, I can't figure out why
Fatal error: Maximum execution time of 30 seconds exceeded
function getHighestIndianPosition ($indians) {
$indians=array_reverse($indians, true);
foreach($indians as $key => $currentIndian){
$sees[$key]=1;
for($checkedIndian=$key-2; $indians[$checkedIndian]<$currentIndian
¦¦ $indians[$checkedIndian]>$indians[$checkedIndian+1]; $checkedIndian--){
$sees[$key]++;
}
if($sees[$key]>=$key-1){
return $key;
$findHighest=1;
break;
}
}
if($findHighest!=1){
$highestSees=0;
foreach($sees as $value){
if($value>$highestSees)$highestSees=$value;
}
$sees=array_flip($sees);
return $sees[$highestSees];
}
}