r/dailyprogrammer • u/Steve132 0 1 • Sep 06 '12
[9/06/2012] Challenge #96 [difficult] (Water Droplets)
Your wet dog rand across your hardwood floor. It drops a series of water droplets randomly across the floor. The water droplets each land at particular positions on your infinite floor, and they each create a wet circle of a given radius across the floor.
What is the total area of wet? The input file will be a list of drop descriptions, one per line. Each drop description is three floating point numbers of the format x0 y0 radius, describing the center of the circle and the radius.
Estimate the area of wet accurate to 3 decimal places.
Example input file:
0.479477 -0.634017 0.137317
-0.568894 -0.450312 0.211238
-0.907263 -0.434144 0.668432
0.279875 0.309700 0.242502
-0.999968 -0.910107 0.455271
0.889064 -0.864342 1.292949
-0.701553 0.285499 0.321359
-0.947186 0.261604 0.028034
0.805749 -0.175108 0.688808
0.813269 -0.117034 0.340474
-0.630897 -0.659249 0.298656
-0.054129 -0.661273 0.270216
0.042748 0.469534 0.759090
0.079393 -0.803786 0.635903
-0.987166 0.561186 0.740386
-0.246960 -0.774309 1.035616
-0.189155 -0.244443 0.187699
0.683683 -0.569687 0.275045
-0.249028 -0.452500 0.713051
-0.070789 -0.898363 0.135069 Example output: (warning: flawed mod solution might be wrong)
Total wet area: 12.065EDIT: I apologize, I generated the radii randomly and didn't notice some were negative. My solution simply takes the absolute value of the radius by default. (I'm using an r2) so it didn't matter. I'm fixing the data now.
12
u/Whyrusleeping Sep 06 '12
So, we have to take into account overlapping yes? or else this would be pointlessly easy.
3
u/winndixie Sep 06 '12
How can a radius be negative?
4
u/phaeilo Sep 10 '12
Messing around with canvas: http://jsfiddle.net/URMN6/1/
3
u/[deleted] Sep 06 '12
I played around with this some, but didn't realize how nasty the math got with arbitrarily overlapping circles. My next plan of attack is to
So I'll have to try that later.
3
u/Cosmologicon 2 3 Sep 06 '12
Numerical solution, gets 9.73178 in 0.18 seconds:
2
u/Ledrug 0 2 Sep 06 '12 edited Sep 06 '12
I can't seem to get the 12.065 answer somehow, my result is 9.73178156212 instead.
2
u/xORioN63 Sep 07 '12 edited Sep 07 '12
Monte Carlo method.
9.73169937322
2
u/Ledrug 0 2 Sep 07 '12
Standard Monte Carlo, with sigma estimates. Not the smartest way for this problem, but it's one way.
0
u/[deleted] Sep 06 '12
Need more details on this, what exactly does each column stand for?
1
u/ILickYu 0 0 Sep 06 '12 edited Sep 06 '12
Here is my c# solution. Not the best way, but it works. The only problem is that for some reason it rounds up to 2 decimal points even though it should be 3. Takes about a second ro run. Got 9.730.
1
u/juntang Sep 08 '12
Hey was hoping to get some help with my code, the general algorithm to me sounds alright? Getting the max/min x/y/ values finding the area of said rectangle, generate a sampleValue number of random values inside that rectangle then check whether they are inside the droplets.
My isIN function to check whether a random point is in the droplets is
and my code, sorry for the horrendous code, is
1
u/PersevereSC 0 0 Sep 10 '12
Java, Monte Carlo
1
u/skeeto -9 8 Sep 10 '12
In Common Lisp, by Monte Carlo method.
Output (taking 3 seconds):
Disappointingly inaccurate, and longer runs don't improve the accuracy. However, this does match my experience of attempting to compute pi by Monte Carlo.