Author |
Topic: Random Connections (Read 2366 times) |
|
Skandh
Junior Member
 

Gender: 
Posts: 77
|
 |
Random Connections
« on: Aug 18th, 2011, 10:45am » |
Quote Modify
|
I was going through some algorithmic puzzles and got bit confused in following problem (the reason could be I usually get nervous when I see probability ) "Random connections. Write a program that takes as command-line arguments an integer N and a double value p (between 0 and 1), plots N equally spaced dots of size .05 on the circumference of a circle, and then, with probability p for each pair of points, draws a gray line connecting them" Let's say I have N=10 equally spaced dots and p=0.3. Hence with the given data we have 45 pair of points. So we have to draw lines between these 45 pairs with probability 0.3. What does this mean?
|
|
IP Logged |
I wanna pull by legs!!!
|
|
|
pex
Uberpuzzler
    

Gender: 
Posts: 880
|
 |
Re: Random Connections
« Reply #1 on: Aug 18th, 2011, 11:37am » |
Quote Modify
|
on Aug 18th, 2011, 10:45am, Skandh wrote:So we have to draw lines between these 45 pairs with probability 0.3. What does this mean? |
| The usual meaning is that each of these 45 lines can be drawn, each independently with a probability of 30%. So, something like for i in 0 to 8 for j = i+1 to 9 draw a random number r, uniform in (0,1) if r < 0.3 draw a line from point i to point j end if end for end for
|
|
IP Logged |
|
|
|
|