Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Non-ending loop


SoulMaster - 12:42 am on Jan 12, 2009 (gmt 0)


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

for($checkedIndian=$key-2; $indians[$checkedIndian]<$currentIndian ¦¦ $indians[$checkedIndian]>$indians[$checkedIndian+1]; $checkedIndian--)

Wont end. I get error:
Fatal error: Maximum execution time of 30 seconds exceeded

Here's the code:

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];
}
}

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.


Thread source:: http://www.webmasterworld.com/php/3824173.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com