View Single Post
  #1  
Old 11-11-2011, 11:59 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
The length of the array is increased to units + 1 to reconcile the idea of each element of the array scaling from the beginning of that index that index to the beginning of the next, IE, 0-1, 1-2, ..., 100-0

It doesn't matter if temp.isgap starts as true or false, and it's possible to see a sort of representation of how the cars align by returning lot instead of this.parkedcars.




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

function 
findMin(unitscarlength){
  
this.parkedcars 0;
  
temp.isgap false;
  for(
temp.0units+1i++){
    
temp.lot.add("E");
  }
  for(
temp.0lot.size(); i++){
    
temp.isgap = !temp.isgap;
    if(!
temp.isgap){
      
lot parkCar(loti);
      
i++;
    }
  }
  return 
this.parkedcars
}

function 
findRand(unitscarlength){
  
temp.int(random(0,2));
  if(
== 0){
    return 
findMin(unitscarlength);
  }
  else{
    return 
findMax(unitscarlength);
  }
}

function 
parkCar(arri){
  if(
== arr.size()){
    
temp.val 0;
  }
  else{
    
temp.val 1;
  }
  if(
arr[i] == "E" && arr[val] == "E"){
    
arr[i] = "C";
    
arr[val] = "C";
    
this.parkedcars++;
  }
  return 
arr;
}

function 
findMax(unitscarlength){
  return 
int((units+1)/carlength); 

Output:
PHP Code:
34
50
42.96 
Reply With Quote