![]() |
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. |
Quote:
|
Alright, this thread has been dead for long enough...
Like I said before, the fact that the lot is circular is important. However, let us consider the first car. With probability 1 it parks somewhere in the lot (since it's empty). Then we can henceforth consider the lot to be linear (and 1 car-length shorter) with one end being the front of the first car and the other the end of the first car. And we have 1 car in our lot. So, f(N; circular) = 1 + f(N-2; linear). So now we consider the second car and a lot of N-2. Somewhere in this lot, the car will park and split our lot into 2 even further smaller lots. If we number the units 0 ... N-3, let us call the smaller unit number that the second car occupies i. After parking, there are lots of size i and N-4-i. So, f(N-2; linear | car 2 parks in unit i) = 1 + f(i; linear) + f(N-4-i; linear). For those of you who know your probability, you'll know that P(Y) = P(Y | X = x1) * P(X = x1) + ... + P(Y | X = xn) * P(X = xn). And for those of you who don't, P is the probability and that | means "given". So, we apply this rule to the above: f(N-2; linear) = 1 + (f(0; linear) + f(N-4; linear)) * P(i = 0) + ... + (f(N-4; linear) + f(0; linear)) * P(i = N-3). Of course, P(i = x) = 1/(N-3), so we can boil this down to f(N; linear) = 1 + 2/(N-1)*(f(0) + ... f(N-2)). When applied, f(100; circular) = 43.233235838... However, the recursion grows with N!! (repeat !s as many times as a car-length... :)), so to speed up this calculation, we use memoization. PHP Code:
|
Looks more like a maths lesson rather then a programming solution. Pretty cool though since I see what you did there, I'll rep you for that.
|
gj on the four people that entered.
|
I'm bad at conceptualizing maths. :(
Can't we have a programming excercise thats like....useful. :3 |
All times are GMT +2. The time now is 04:35 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.