![]() |
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. |
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 |
Quote:
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:
PHP Code:
|
Quote:
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. |
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
|
Quote:
2. The cars are parallel parking AROUND a circle. 3. Nope. |
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? http://i.imgur.com/Cf4ZK.png |
Quote:
|
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?
|
Quote:
|
Quote:
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. |
Quote:
|
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:
This is the best I could come up with, tell me if I'm along the right lines. >_< |
1 Attachment(s)
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). |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
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 |
How many floors does this parking lot contain?
|
Quote:
Quote:
|
Maybe just make a normal car park and you'd be right.
|
Quote:
|
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:
PHP Code:
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. |
Quote:
|
Quote:
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 |
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:
PHP Code:
|
1 Attachment(s)
Quote:
|
Not gonna lie, I see this circular parking lot as this.
http://i1206.photobucket.com/albums/.../burnmoney.jpg and time |
lmao.
|
Quote:
Quote:
|
Quote:
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? |
I ended up with something like this:
PHP Code:
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:
|
Quote:
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. |
none because crono crushed them all in his monster truck!
|
Oh how I wish Stefan would implement the equivalent of a like button.
*Likes Crono's post 1000 times* |
Quote:
Close enough. |
Too bad you can only like a post once a day x_x
|
Quote:
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. |
All times are GMT +2. The time now is 03:26 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.