All pastes #272159 Raw Edit

Unnamed

public php v1 · immutable
·published 2006-12-08 19:57 UTC
rendered paste body
<?phpdefine('cashcost', 120);define('chrcost', 10);define('strcost', 1);$cash = 280726;$chr = 785;$str =  3362;$curbuildings = 0;/*$buildings = 308;$psize = 114;*/$planets = array(	array(		'buildings'	=>	308,		'size'		=>	114	),	/*array(		'buildings'	=>	538,		'size'		=>	250	),	array(		'buildings'	=>	912,		'size'		=>	228	)*/);function getOB($size, $buildings){	$ob = 100 * (exp($buildings/(4*$size)) - exp(1/4));	$ob = ($ob < 0) ? 0 : $ob;	return $ob;}function getBuildings($psize, $buildings){	global $cash, $chr, $str;		$curbuildings = 0;	$ccash = $cash;	$cchr = $chr;	$cstr = $str;		echo "Looking at a planet with a capacity of ".$psize." and a current amount of buildings of ".$buildings."<br />\n";	echo "Starting off with an OB percentage of ", round(getOB($psize, $buildings), 2), "%.<br />\n";	do	{		$curOB = getOB($psize, $curbuildings + $buildings);		$ob_cash = cashcost * (1 + ($curOB/100));		$ob_chr = chrcost * (1 + ($curOB/100));		$ob_str = strcost * (1 + ($curOB/100));				$ccash -= $ob_cash;		$cchr -= $ob_chr;		$cstr -= $ob_str;				$curbuildings++;	}	while(($ccash >= $ob_cash) && ($cchr >= $ob_chr) && ($cstr >= $ob_str));		echo "You could build ".$curbuildings." banks on this planet with an end OB of ".round($curOB, 2)."%.<br /><br />\n";		return $curbuildings;}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Bank Building</title></head><body><?phpecho "<strong>Reserves:</strong><br />\n";echo "Cash: ", $cash, "<br />\n";echo "Chromium: ", $chr, "<br />\n";echo "Stontium: ", $str, "<br /><br />\n";foreach($planets as $planet){	$tobuild[$planet['size']] = getBuildings($planet['size'], $planet['buildings']);}asort($tobuild);$best = array_slice($tobuild, -1, 1, true);foreach($best as $planet => $buildings)	echo "The best is to build ".$buildings." banks on the planet with size ".$planet;?></body></html>