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-08-2011, 09:11 PM
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
Programming Exercise #8: Parking

It has been more than a year since the last programming exercise! So, I thought I'd give it another go. Today's puzzle is about a circular parking lot.

Now, let's suppose that cars are two units long and that our parking lot is N units long, arranged along the circumference of a circle. Cars come and park randomly in the parking lot in any space that can accommodate them (that is, any space that is at least 2 units long).

We wait until there are no spaces left. How many cars do we expect to find in our parking lot? In other words, if we counted the cars in our parking lot every day til the end of time, what would the average be?

This thread is about discussing methods of solving this problem. If you've seen this problem before, you can aid in the discussion, but let's wait some time before ruining the fun for everyone. Otherwise, when you have an answer, post the code and the output for when N = 100.
__________________
◕‿‿◕ · 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
  #2  
Old 11-08-2011, 10:46 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
You're asking how many times 2 goes into 100? lol
Anyhow if it's not and I mis-interpreted the question and the length of a car is 2 units as well as the width... then I'd:
1)Find the original radius:
100=2*pi*r
100/2/pi=r
r=15.9(rounded)

2)then subtract 2 units(length of the car) from that
r=13.9

3)Find the new circumfrence
circ=2*pi*13.9
circ=87.3(rounded)

The amount of cars able to fit in the parking lot is now:
=86/2
=43

Last edited by Tricxta; 11-08-2011 at 10:56 PM..
Reply With Quote
  #3  
Old 11-08-2011, 10:50 PM
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 Tricxta View Post
You're asking how many times 2 goes into 100? lol
Well if 50's your answer, then you're wrong.

Let's consider a linear lot and the case on N=4:
1/2 of the time, you will have two cars in the lot:
PHP Code:
[][][][] t0
car 
[][] t1
car car  t 
t2 
But sometimes it's just 1:
PHP Code:
[][][][] t0
[]car [] t1 
So the answer in this case is 1.5.
__________________
◕‿‿◕ · 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
  #4  
Old 11-08-2011, 10:50 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Tricxta View Post
You're asking how many times 2 goes into 100? lol
Except the 100 is circular rather than a square, so it's not an exact fit.

Also I swear had I paid attention on this specific maths in school, this would have been the first time it would have been any use to me some 7 years later.
Reply With Quote
  #5  
Old 11-08-2011, 11:00 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
I'm a bit confused with this challenge, don't we also need the width of the car? assuming its the length that's already been given
Reply With Quote
  #6  
Old 11-08-2011, 11:02 PM
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 Tricxta View Post
Anyhow if it's not and I mis-interpreted the question and the length of a car is 2 units as well as the width... then I'd:
1)Find the original radius:
100=2*pi*r
100/2/pi=r
r=15.9(rounded)

2)then subtract 2 units(length of the car) from that
r=13.9

3)Find the new circumfrence
circ=2*pi*13.9
circ=87.3(rounded)

The amount of cars able to fit in the parking lot is now:
=86/2
=43
1. The width of a car has nothing to do with the problem.
2. The cars are parallel parking AROUND a circle.
3. Nope.
__________________
◕‿‿◕ · 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
  #7  
Old 11-08-2011, 11:14 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
So let me get this right then I'll leave this thread alone :P
The question basically is how many cars of the length 2 units can you fit into a car park with the outer radius of 100 units whilst having the cars parked as shown?
Reply With Quote
  #8  
Old 11-08-2011, 11:16 PM
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 Tricxta View Post
So let me get this right then I'll leave this thread alone :P
The question basically is how many cars of the length 2 units can you fit into a car park with the outer radius of 100 units whilst having the cars parked as shown?
This would be a perfect packing of the cars, yes. In this case, 50 cars could fit in a lot of 100 units. However, they are parking randomly, so the cars are unlikely to park perfectly packed (say that 5x fast).
__________________
◕‿‿◕ · 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
  #9  
Old 11-08-2011, 11:22 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
If the cars are parking randomly and leaving gaps too small for other cars to fit we can only come up with an algorithm to determine the average over a given time but no actual answer. Right?
Reply With Quote
  #10  
Old 11-08-2011, 11:26 PM
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 Tricxta View Post
If the cars are parking randomly and leaving gaps too small for other cars to fit we can only come up with an algorithm to determine the average over a given time but no actual answer. Right?
Which is the problem, isn't it!
__________________
◕‿‿◕ · 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
  #11  
Old 11-09-2011, 09:10 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by Tolnaftate2004 View Post
Which is the problem, isn't it!
What you mean to say is yes.

To be totally honest with you, would you ever need to design this system on Graal?

Make the challenges based on Graal stuff which can help new developers, you could have done something Halloween based or thanks giving, not a car park.
__________________
Reply With Quote
  #12  
Old 11-09-2011, 12:08 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
To be totally honest with you, would you ever need to design this system on Graal?
No. Programming exercises are not about things you may or may not need, though. They present problems for you to reflect on. Complicated problems that, when solved, can give you an idea on how to tackle similar ones in the future.
Reply With Quote
  #13  
Old 11-09-2011, 06:37 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
Well, I was trying to come up with some sort of algorithm for this which took into account the largest potential area the cars could take up, as well as the least amount of area the cars could take up, and came up with this. The problem is, I can only work it out if the width of the cars are known, as I don't really know how this can be solved without knowing this.

PHP Code:
function onCreated(){
  
  
temp.100;
  
temp.car_length 2;
  
temp.car_width 2;    // Because I can't do it with an unknown value

  /* Using Pythagoras' theorm, I found the hypotenuse of the triangle inside 
      the car, which also gave me the radius of the circle around the car,
      which represents the total amount of area it could potentially take up, as
      they are parking randomly.
  */
  
temp.car_potential_area = ((car_length 2)^+ (car_width 2)^2)^0.5;
  
  
/* I then used the radius of the circle found above so that I could
      calculate the length of the radius between the center of the inner
      circle and the center of the car's "circle"
  */
  
temp.car_middle = (pi 2) + car_potential_area;

  
/* And then, using the radius from above, calculated how many cars 
      could fit along the circumference of this line, like beads on a string
      if you imagine the circles around the cars.
  */
  
temp.parking_places pi car_middle;

  
/* From this, I divided the total parking space by the diameter of the
      circle of potential area they could take up, to get a decimal value
      for the number of cars.
  */
  
temp.cars parking_places / (car_potential_size 2);

  
// Echoes a value for the minimum number of cars (38 cars)
  
echo(int(temp.cars)); // Integer because you can't have a fraction of a car

  /* A value for the maximum number of cars, parking side by side around the
      circle
  */
  
temp.max_cars parking_places car_length;

  
// Echoes a value for the maximum number of cars if they were lined up side by side (54 cars)
  
echo(int(temp.max_cars));

So my answer is that there could be any number between 38 and 54 cars in the parking lot.
This is the best I could come up with, tell me if I'm along the right lines.
__________________

Intelligence without ambition is like a bird without wings.


Last edited by iBeatz; 11-09-2011 at 07:01 PM..
Reply With Quote
  #14  
Old 11-09-2011, 07:17 PM
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
I don't know where you guys are getting pi from, the lot is 100 units and a car is 2 units, so the very most you could fit around the circle is 50 cars and if every car left a space behind it, the very least you could have is 34 cars. So the answer is somewhere in there (it's not an integer).

I've attached a picture of a possible outcome for a lot of N=21. Blue are cars, black is left-over spaces that a car cannot fit into (that is, they are 1 unit long).
Attached Images
 
__________________
◕‿‿◕ · 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 :/

Last edited by Tolnaftate2004; 11-09-2011 at 07:36 PM..
Reply With Quote
  #15  
Old 11-09-2011, 07:23 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
Quote:
Originally Posted by Tolnaftate2004 View Post
I don't know where you guys are getting pi from, the lot is 100 units and a car is 2 units, so the very most you could fit around the circle is 50 cars (but this is not the answer).
How could you not use pi to solve this? o_o
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #16  
Old 11-09-2011, 07:38 PM
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 iBeatz View Post
How could you not use pi to solve this? o_o
Because the lot isn't 100*pi or 4*arctan(1/5)-arctan(1/239) or sqrt(1+sqrt(1+sqrt(1+...))) units, it's 100 units.
__________________
◕‿‿◕ · 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
  #17  
Old 11-09-2011, 09:16 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by Crow View Post
No. Programming exercises are not about things you may or may not need, though. They present problems for you to reflect on. Complicated problems that, when solved, can give you an idea on how to tackle similar ones in the future.
Maybe more than one person will participate next time. Who knows
__________________
Reply With Quote
  #18  
Old 11-09-2011, 09:22 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
Maybe more than one person will participate next time. Who knows
I can't see this being over yet.
Reply With Quote
  #19  
Old 11-10-2011, 12:22 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
They could:

1. Paint the lines so there's at least 2.5 units of space for each car.
2. Have offenders towed/exploded for not staying within the lines of their spot.

So the solution to me is N / 2.5
__________________
Quote:
Reply With Quote
  #20  
Old 11-10-2011, 12:29 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
How many floors does this parking lot contain?
Reply With Quote
  #21  
Old 11-10-2011, 10:35 PM
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 fowlplay4 View Post
They could:

1. Paint the lines so there's at least 2.5 units of space for each car.
2. Have offenders towed/exploded for not staying within the lines of their spot.

So the solution to me is N / 2.5
Heh, nope.

Quote:
Originally Posted by ffcmike View Post
How many floors does this parking lot contain?
Just 1.
__________________
◕‿‿◕ · 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
  #22  
Old 11-10-2011, 11:27 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Maybe just make a normal car park and you'd be right.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #23  
Old 11-11-2011, 02:57 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Quote:
Originally Posted by Gunderak View Post
Maybe just make a normal car park and you'd be right.
Why not test out your theory? Tolnaftate will tell you if you're correct or not
Reply With Quote
  #24  
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
  #25  
Old 11-11-2011, 08:01 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
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...
Gaps between cars should be either 0 units or 1 unit. The cars have to line up with the units. Additionally, the lot being circular does have an impact on the answer, but somehow considering it as a linear lot is a step in the right direction.
__________________
◕‿‿◕ · 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
  #26  
Old 11-11-2011, 11:25 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
Quote:
Originally Posted by Tolnaftate2004 View Post
Gaps between cars should be either 0 units or 1 unit. The cars have to line up with the units. Additionally, the lot being circular does have an impact on the answer, but somehow considering it as a linear lot is a step in the right direction.
the only significant impact I can see from the lot being circular is the relationship of the car at the theoretical start and ending points, meaning if a car were attempted to be parked at N-1 marker, it should then consider if there is a car at 1 or 2 (0 or 1 as array form).

I'll adjust for that and shift to using an array since the gaps remaining integer makes the question tremendously easier.

Or it'd be getting more complex into relational math where the fact that the car is tangent to whatever point on the circle has some profound effect on how the cars can align and modifying the math to account for that but I don't think that's what you were going for
Reply With Quote
  #27  
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
  #28  
Old 11-11-2011, 12:24 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by Tricxta View Post
Why not test out your theory? Tolnaftate will tell you if you're correct or not
Attached Thumbnails
Click image for larger version

Name:	Carpark.PNG
Views:	136
Size:	10.0 KB
ID:	53924  
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 11-11-2011 at 03:46 PM..
Reply With Quote
  #29  
Old 11-11-2011, 06:12 PM
Fulg0reSama Fulg0reSama is offline
Extrinsical Anomaly
Fulg0reSama's Avatar
Join Date: Sep 2009
Location: Ohio
Posts: 3,049
Fulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant future
Not gonna lie, I see this circular parking lot as this.


and time
__________________

Careful, thoughts and opinions here scare people.
Reply With Quote
  #30  
Old 11-11-2011, 06:17 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
lmao.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #31  
Old 11-11-2011, 06:18 PM
WanDaMan WanDaMan is offline
Master Tux
WanDaMan's Avatar
Join Date: Aug 2002
Location: England, United Kingdom
Posts: 5,571
WanDaMan is a jewel in the roughWanDaMan is a jewel in the rough
Send a message via MSN to WanDaMan
Quote:
Originally Posted by Tolnaftate2004 View Post
We wait until there are no spaces left.
Then :

Quote:
Originally Posted by Tolnaftate2004 View Post
N = 100.
__________________
V$:CONFL16T
Reply With Quote
  #32  
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
  #33  
Old 11-12-2011, 01:57 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
I ended up with something like this:

PHP Code:
function onCreated() {

  
temp.4// Amount of Slots in Units
  
temp.2// Length of Cars in Units
  
  
temp.parking_available = new[temp.n];

  
this.tick 0;
  
this.cars_sum 0;
  
this.cars_min 0;
  
this.cars_max 0;
  
this.cars_sample 0;
  
this.tracking = {};
  
  
findParking(temp.parking_available1temp.l);

  
temp.avg this.cars_sum this.cars_sample;
  echo(
"Sample Size: " this.cars_sample);
  echo(
"Min: " this.cars_min);
  echo(
"Max: " this.cars_max);
  echo(
"Sum: " this.cars_sum);
  echo(
"Average: " temp.avg);
}

function 
findParking(temp.slotstemp.cartemp.car_length) {
  
// Find Possible Spots
  
temp.spots findPossibleSpots(temp.car 1temp.slots.link(), temp.car_length);
  
temp.spots_count temp.spots.size();
  if (
temp.spots_count 1) {
    
// Avoid Crashing Server
    
this.tick++;
    if (
this.tick == 1000) {
      
//echo("Calculating..." SPC timevar2);
      
this.tick 0;
      
sleep(0.05);
    }
    for (
temp.spottemp.spots) {
      
temp.updated_slots parkInSpot(temp.slotstemp.spottemp.cartemp.car_length);
      
findParking(temp.updated_slotstemp.car 1temp.car_length);
    }
  } else {
    
// No Parking Available for Car
    // Add Amount of Cars that did Find Parking
    // Increment Sample Size
    
temp.cars = (temp.spots_count == temp.car temp.car 1);
    
this.cars_sum += temp.cars;
    
this.cars_sample++;
    
this.cars_min = (this.cars_min == 0) ? temp.cars min(this.cars_mintemp.cars);
    
this.cars_max = (this.cars_max == 0) ? temp.cars max(this.cars_maxtemp.cars);
    
this.tracking.add(temp.slots);
  }
}

function 
parkInSpot(temp.slotstemp.spottemp.cartemp.car_length) {
  
temp.car_slots = {};
  
temp.car_slots.addarray(temp.slots);
  for (
temp.0temp.temp.car_lengthtemp.i++) {
    
temp.car_slots[temp.spot temp.i] = true;
  }
  return 
temp.car_slots;
}

function 
findPossibleSpots(temp.last_cartemp.slotstemp.car_length) {
  
temp.found = {};
  
temp.max   temp.slots.size();
  for (
temp.itemp.slots.indices(0)) {
    
temp.canpark true;
    for (
temp.0temp.temp.car_length && temp.canparktemp.j++) {
      
temp.temp.temp.j;
      if (
temp.slots[temp.k] > || temp.== temp.max) {
        
temp.canpark false;
      }
    }
    if (
temp.canpark) {
      
temp.found.add(temp.i);
    }
  }
  return 
temp.found;

Which recursively generates every possible combination that the parking lot can accept. When the parking lot is full then it records the amount of cars the combination could take add it's to the sum and increases the sample size.

I don't think that's the 'linear' way though since when N=4 I get 1.666_. If I track the patterns and ignore ones that have already been generated I get the right answer for N=4.

I'm guessing there's a much better way of going about this than brute force since I can't even calculate an answer where N=100 with the (npcserver).
__________________
Quote:

Last edited by fowlplay4; 11-12-2011 at 07:04 PM..
Reply With Quote
  #34  
Old 11-12-2011, 02:58 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 fowlplay4 View Post
I ended up with something like this:

snip

I don't think that's the 'linear' way though since when N=4 I get 1.666_. If I track the patterns and ignore ones that have already been generated I get the right answer for N=4.
I think you're close. 1.666 may be due to treating the circular lot as if it were linear? I can't really tell...
__________________
◕‿‿◕ · 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
  #35  
Old 11-12-2011, 03:30 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Tolnaftate2004 View Post
I think you're close. 1.666 may be due to treating the circular lot as if it were linear? I can't really tell...
These would be the full combinations (N=4):

1122
0110
2211

(2 + 1 + 2) / 3 = 1.666_

If we don't care about the order:

1111
0110

(2 + 1) / 2 = 1.5

Like in your example. The code I have edited in there ignores the order so I do get 1.5 with it, problem is that it has to go through all the permutations first so it scales horribly.
__________________
Quote:
Reply With Quote
  #36  
Old 11-12-2011, 03:57 AM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
none because crono crushed them all in his monster truck!
__________________
Reply With Quote
  #37  
Old 11-12-2011, 06:12 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Oh how I wish Stefan would implement the equivalent of a like button.
*Likes Crono's post 1000 times*
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #38  
Old 11-12-2011, 06:58 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
Quote:
Originally Posted by Gunderak View Post
Oh how I wish Stefan would implement the equivalent of a like button.
*Likes Crono's post 1000 times*
Like

Close enough.
__________________

Reply With Quote
  #39  
Old 11-12-2011, 07:21 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Too bad you can only like a post once a day
Reply With Quote
  #40  
Old 11-12-2011, 08:15 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 fowlplay4 View Post
These would be the full combinations (N=4):

1122
0110
2211

(2 + 1 + 2) / 3 = 1.666_

If we don't care about the order:

1111
0110

(2 + 1) / 2 = 1.5
The example I gave was wrong, unfortunately. I can't edit that post. it should be 1.666...
The number of cars that can fit in a lot of size 4 is 2. No matter where the first car parks, there is always room for the second car.
__________________
◕‿‿◕ · 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 :/

Last edited by Tolnaftate2004; 11-12-2011 at 08:30 AM..
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:47 AM.


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