It's probably not wise to assume that you just easily solved a 100+ year old unsolved mathematical problem.
It's probably not wise to assume that you just easily solved a 100+ year old unsolved mathematical problem.
I don't believe that this approach makes any assumptions about the chords that it generates. Here's a ruby snippet that does just that (err, I think!)
plane_size = 10000.0 chords = []
while chords.size < 100 p1 = {} p2 = {}
p1[:x] = Random.rand(plane_size) - plane_size / 2
p1[:y] = Random.rand(plane_size) - plane_size / 2
p2[:x] = Random.rand(plane_size) - plane_size / 2
p2[:y] = Random.rand(plane_size) - plane_size / 2
puts p1
puts p2
#gradient 'm'
m = (p2[:y] - p1[:y]) / (p2[:x] - p1[:x])
#y = mx + b
# => b = y - mx
b = p2[:y] - m * p2[:x]
#x^2 + y^2 = 1
#sub in y from the line equation
#x^2 + (mx + b) * (mx + b) = 1
#x^2 + m^2x^2 + 2bmx + b^2 = 1
#x^2(1 + m^2) + 2bmx + b^2 - 1 = 0
#apply the quadratic equation to find the roots
#Ax^2 + Bx + C = 0
#=>x = (-B +- sqrt(b^2 - 4AC)) / 2A
#in our case, A = (1 + m^2), B = 2bm, C = b^2 -1
#the line intersects if B^2 -4AC > 0
discriminator = (2 * b * m) * (2 * b * m) - 4 * (1 + m * m) * (b * b - 1)
if discriminator > 0 then
chord1 = {}
chord2 = {}
chord1[:x] = (-2 * b * m + Math.sqrt(discriminator) ) / (2 * (1 + m * m))
chord1[:y] = m * chord1[:x] + b
chord2[:x] = (-2 * b * m - Math.sqrt(discriminator) ) / (2 * (1 + m * m))
chord2[:y] = m * chord2[:x] + b
length = Math.sqrt((chord2[:x] - chord1[:x]) * (chord2[:x] - chord1[:x]) +
(chord2[:y] - chord1[:y]) * (chord2[:y] - chord1[:y]))
chords << length
end
end
smaller = 0
chords.each {|c| smaller += 1 if c < Math.sqrt(3) }
puts "The number of chords smaller than sqrt(3) = #{smaller/100.0}%"
If I believe the result, the real world seems to feel that the answer is 0.5Edit: Hah! Should have read just a few comments further, and I would have seen some other posts doing exactly the same thing. Good to see we ended up with the same answer :D
For this Ruby snippet, you chose random (x,y) coordinate pairs on a plane. This corresponds to selection method #2 as outlined on the Wikipedia article [0]. Scroll down a bit to see different selection methods visualized!
[0] https://en.wikipedia.org/wiki/Bertrand_paradox_%28probabilit...