View Single Post
  #9  
Old 11-11-2011, 03:45 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Began the equation by assuming the fact that the lot was circular was essentially an extra detail that mattered very little to the eventual outcome since the circumference can basically be regarded as a circle laid out flat. So assuming a 100 unit long straight line, and a gap of 1 unit between the cars as the highest gap (rather than say 1.99999 repeated which would lead to 25 cars instead of whatever limit you said later), came up with this code that would linearly determine how many cars would fit.

PHP Code:
function onCreated(){
  
temp.val1 findMin(1002);
  
temp.val2 findMax(1002);
  echo(
val1);
  echo(
val2);
  for(
temp.0100i++){
    
temp.val3 += findRand(1002);
  }
  echo(
val3/100);
}

function 
findRand(ni){
  
temp.space 0;
  
temp.gap random(12);
  
temp.isgap false;
  
temp.cars 0;
  while(
space n){
    
isgap = !isgap;
    if(
isgap){
      
space += gap;
    }
    else{
      
space += i;
      
cars++;
    }
  }
  return 
cars;
}

function 
findMin(ni){
  
temp.space 0;
  
temp.gap 1;
  
temp.isgap false;
  
temp.cars 0;
  while(
space n){
    
isgap = !isgap;
    if(
isgap){
      
space += gap;
    }
    else{
      
space += i;
      
cars++;
    }
  }
  return 
cars;
}

function 
findMax(ni){
  return 
int(n/i);

Output:
PHP Code:
33
50
40.87 

The results if plotted for each random iteration would wind up being a sort of diamond leading around the value of min + max / 2, causing the average to approach that value.
Reply With Quote