Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 11-12-2011, 01:29 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Mark Sir Link View Post
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

snip
As best as I can tell, this is just an expensive way to compute (min+max)/2, which isn't right.

My hint would be to first consider the lot when it is empty; the first car comes along and parks anywhere at all. After this event, we have 1 car in the lot and the lot is now linear (the endpoints being the front and end of our first car). On top of that, the size of the lot has shrunken to N-2. Then you just have to consider every possible arrangement of cars in a linear lot of length N-2.

What do you have after the next car arrives?
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
Reply


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

Forum Jump


All times are GMT +2. The time now is 01:23 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.