Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Contests > PHP Programming Contests

PHP Programming Contests Everything to do with the PHP Programming Contests.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2003-08-25, 04:55 PM
stuart's Avatar
Administrator
 
Join Date: Jan 2003
Location: Scotland
Posts: 472
stuart will become famous soon enoughstuart will become famous soon enough
Send a message via MSN to stuart
Default

At last I finally made time to release the Pizza Dude contest results

Very surprising results - nearly everyone got the same solution. Time ended-up being the decider.

I decided to keep the dest and map pretty short, only slightly larger the the demo one given.

Anyway you all done fantastic - check out the archive page to see how others coded their solution, I intend to dig a bit deaper too (when I get time).

I have not emailed anyone yet regarding prizes. Prizes are all canceled this month.........

Only joking, I will email everyone tomorrow regarding the prizes Watch your mail box dudes, you might get a prizes you didn't expect

Untill next time....

Stuart
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2003-08-25, 11:28 PM
Junior Member
 
Join Date: Jun 2003
Location: Sacramento, CA, USA
Posts: 9
lrutledge
Send a message via AIM to lrutledge
Default

Congratulations to the winners!
Reply With Quote
  #3 (permalink)  
Old 2003-08-26, 04:08 AM
Junior Member
 
Join Date: Aug 2003
Posts: 3
FryGuy
Default

Congratulations to everyone that won. I did much better than I thought I would do, so I'm happy
Reply With Quote
  #4 (permalink)  
Old 2003-08-26, 07:13 PM
Junior Member
 
Join Date: Aug 2003
Posts: 2
Transistor
Default

Hi,
thank you for the congratulations.
Here is my solution including the annotations. ...if somebody is interested

Code:
<?php
$time_start = getmicrotime();
$try = 0;
//////////////////////////////////////////////////////
$iResultLength = -1;  	// result length
$arrResultPath = array();  // result path

// load map
$arrNodes = $arrNodeToWay = $arrNodeFromWay = array();
foreach(file("map.txt") as $sLine){
	$arrLine = explode(" ",strtoupper(trim($sLine)));
	if((sizeof($arrLine)==4) && $arrLine[0]!=$arrLine[2]){	// ignore empty/damaged lines and routes that start and end at the same point
 if(!isset($arrNodes[$arrLine[0]][$arrLine[2]]) || $arrNodes[$arrLine[0]][$arrLine[2]]>$arrLine[1]){
 	$arrNodes[$arrLine[0]][$arrLine[2]] = $arrLine[1];
 	if(!isset($arrNodeToWay[$arrLine[2]]) || $arrLine[1]<$arrNodeToWay[$arrLine[2]]){
  $arrNodeToWay[$arrLine[2]] = $arrLine[1];
 	}
 	if(!isset($arrNodeFromWay[$arrLine[0]]) || $arrLine[1]<$arrNodeFromWay[$arrLine[0]]){
  $arrNodeFromWay[$arrLine[0]] = $arrLine[1];
 	}
 }
 if($arrLine[3]==2){    	// bidirectional
 	if(!isset($arrNodes[$arrLine[2]][$arrLine[0]]) || $arrNodes[$arrLine[2]][$arrLine[0]]>$arrLine[1]){
  $arrNodes[$arrLine[2]][$arrLine[0]] = $arrLine[1];
  if(!isset($arrNodeToWay[$arrLine[0]]) || $arrLine[1]<$arrNodeToWay[$arrLine[0]]){
  	$arrNodeToWay[$arrLine[0]] = $arrLine[1];
  }
  if(!isset($arrNodeFromWay[$arrLine[2]]) || $arrLine[1]<$arrNodeFromWay[$arrLine[2]]){
  	$arrNodeFromWay[$arrLine[2]] = $arrLine[1];
  }
 	}
 }
	}
}

// take the shortes way first
reset($arrNodes);
while(list($sKey,) = each($arrNodes)){
	asort($arrNodes[$sKey],SORT_NUMERIC);
}

// load delivery instructions
$arrDelivery = array();
foreach(file("dest.txt") as $sLine){
	if($sLine = trim($sLine)) $arrDelivery = explode(" ",strtoupper($sLine));
}
$sDelivery = implode("",$arrDelivery);
#usort($arrDelivery,"cmpDeliveryNode");
$arrCountDelivery = array_count_values($arrDelivery);

// calculate delivery route
foreach($arrDelivery as $sStartPoint){
	if(isset($GLOBALS["arrNodes"][$sStartPoint])){	// if there is at least one destination node
 processNode(array($sStartPoint),0);
	}
}
echo implode(" ",array_intersect($arrResultPath,$arrDelivery))." ".$iResultLength." ".$try;

function processNode($arrPath,$iLength){

	global $arrNodes,
 	$arrCountDelivery,
 	$arrDelivery,
 	$sDelivery,
 	$arrNodeFromWay,
 	$arrNodeToWay,
 	$iResultLength,
 	$arrResultPath;

++$GLOBALS["try"];

	$sPath = implode("",$arrPath);
	$iStartElement = end($arrPath);
	$iLastElement = prev($arrPath);
	$arrCountPath = array_count_values($arrPath);

	// not yet processed points first
	$arrFirst = $arrSecond = $arrThird = array();
	foreach($arrNodes[$iStartElement] as $sDest=>$iLengthDest){

 if(!isset($arrCountPath[$sDest])){
 	if(isset($arrCountDelivery[$sDest])){
  $arrFirst[$sDest] = $iLengthDest; 	// not visited but on delivery route
 	}
 	else{
  $arrSecond[$sDest] = $iLengthDest; 	// not visited and not on route
 	}
 }
 else{
 	// ignore this when B is not on route for A B (A) or has been visited already
 	if($iLastElement !== $sDest || ($arrCountPath[$iStartElement]<2 && isset($arrCountDelivery[$iStartElement]))){
  $arrThird[$sDest] = $iLengthDest;  // already visited
 	}
 }
	}

	$arrTodo = array_diff($arrDelivery,$arrPath);
	foreach($arrFirst+$arrSecond+$arrThird as $sDest=>$iLengthDest){

 $iEstimatedMinLength = $iTmpLength = $iLength+$iLengthDest;

 $arrPathTmp = $arrPath;
 $arrPathTmp[] = $sDest;
 $arrTodoTmp = $arrTodo;
 if(($iDestKey = array_search($sDest,$arrTodoTmp))!==FALSE){
 	unset($arrTodoTmp[$iDestKey]);
 }
 if($arrTodoTmp && !array_intersect($arrTodoTmp,array_keys($arrNodes[$sDest]))){
 	$iEstimatedMinLength += $arrNodeFromWay[$sDest];
 }
 foreach($arrTodoTmp as $sDeliveryElement){
 	$iEstimatedMinLength += $arrNodeToWay[$sDeliveryElement];
 }
 // path longer than found one 
 if($iResultLength>=0 && $iEstimatedMinLength>=$iResultLength){
 	continue; // maybe another way is shorter -> go on
 }
 // all points processed -> shortest way found
 if(!$arrTodoTmp){
 	$iResultLength = $iTmpLength;
 	$arrResultPath = $arrPathTmp;
# 	echo implode("",$arrPathTmp).": $iTmpLength\n";
 	break; 	// this was the last missing point -> skip the rest
 }

 // don't drive useless circles again and again
 if(($iPos = strrpos($sPath,$sDest))!==FALSE){
 	$sSearch = substr($sPath.$sDest,$iPos+1);
 	$sSearchLength = strlen($sSearch);
 	if((strcspn($sSearch,$sDelivery)===$sSearchLength-1)  	// no destination point in circle
   || substr($sPath,($sSearchLength*-2)+1,$sSearchLength)===$sSearch	// ABCABC
   || strpos($sPath,$sDest.$sSearch)!==FALSE){   // A BCDB EFG BCDB
  continue;	// maybe another way is better -> go on
 	}
 }
 if(isset($arrNodes[$sDest])){	// if there is at least one destination node
 	processNode($arrPathTmp,$iTmpLength);
 }
	}
}

// nodes with less and longer connections first
function cmpDeliveryNode($a,$b){
	global $arrNodes;
	if(isset($arrNodes[$a]) && isset($arrNodes[$b])){
 $aSize = sizeof($arrNodes[$a]);
 $bSize = sizeof($arrNodes[$b]);
 if($aSize==$bSize){
 	if($aSize==1){
  $aLength = end($arrNodes[$a]);
  $bLength = end($arrNodes[$b]);
  if($aLength==$bLength) return 0;
  else return($aLength>$bLength)?-1:1;
 	}
 	else return 0;
 }
 else return($aSize<$bSize)?-1:1;
	}
	else return 0;
}

//////////////////////////////////////////////////////
echo "\n\n".(getmicrotime()-$time_start);

function getmicrotime(){
	list($usec, $sec) = explode(" ",microtime());
	return ((float)$usec + (float)$sec);
}
?>
Transistor
Reply With Quote
  #5 (permalink)  
Old 2003-08-30, 03:55 AM
Guest_cagrET
Guest
 
Posts: n/a
Default

gratz to the winner B)
Reply With Quote
  #6 (permalink)  
Old 2003-08-30, 03:58 AM
Guest_cagrET
Guest
 
Posts: n/a
Default

Torsten Rentsch

what is his nick ?
Reply With Quote
  #7 (permalink)  
Old 2003-09-02, 05:53 PM
Junior Member
 
Join Date: Aug 2003
Posts: 2
Transistor
Default

Quote:
Originally posted by Guest_cagrET@Aug 30 2003, 02:58 AM
Torsten Rentsch

what is his nick ?
Transistor == Torsten Rentsch

Transistor
Reply With Quote
  #8 (permalink)  
Old 2003-09-08, 10:32 PM
Junior Member
 
Join Date: Jun 2003
Posts: 12
ciaccia
Default

Hi,

I hadn't time yet to post my reply, and I'm doing it only now...

My special thanks to stuart and all the php-editors staff, and congratulation to all who entered the contest!
__________________
Matteo Beccati
www.phpadsnew.com
www.phppgads.com
Reply With Quote
  #9 (permalink)  
Old 2004-07-24, 12:11 PM
RussianBeauty
Guest
 
Posts: n/a
Default

** removed for spammieness **
Reply With Quote
  #10 (permalink)  
Old 2004-07-25, 10:22 AM
Moderator
 
Join Date: May 2004
Location: Portugal
Posts: 143
gesf is an unknown quantity at this point
Send a message via ICQ to gesf Send a message via MSN to gesf Send a message via Skype™ to gesf
Default

Congratulations to all of the participants, i believe they all made a great job!
__________________
Best Regards,
Gonçalo "GesF" Fontoura

Website : gesf.org
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:50 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.