News for hackers. Stuff that matters.
Re:Bertrand's Paradox by dstyrb on Tuesday August 04, 2015 @12:42AM (#10001695)
I was wrong. My initial approach appears to be the ninja approach like sampo said above. I got 50% -_-

    import numpy as np
    import random as rnd
    import math as m

    chords = []
    samp = 10000
    for c in range(samp):
        #random point on infinite plane is described by a  single coordinate
        dist = rnd.uniform(1., 1000.)
        #DO NOT KNOW HOW TO DO INTERNAL SLICES

        #ignore all possible lines that do not intesect circle
        xsec_half = m.atan(1./dist)
        angle = rnd.uniform(-xsec_half, xsec_half)

        #make 2 points on the randomly chosen line
        x1, y1 = -dist, 0
        x2, y2 = dist, 2*dist*m.tan(angle)

        #copy and paste some shit from wolfram alpha
        dx = x2-x1
        dy = y2-y1
        dr = (dx**2 + dy**2)**0.5
        D = x1*y2 - x2*y1
        
        sqr = (dr**2 - D**2)**0.5

        xa = (D*dy + np.sign(dy)*dx*sqr) / (dr**2)
        xb = (D*dy - np.sign(dy)*dx*sqr) / (dr**2)

        ya = (-D*dx + np.abs(dy)*sqr) / (dr**2)
        yb = (-D*dx - np.abs(dy)*sqr) / (dr**2)

        chords.append(((xa-xb)**2 + (ya-yb)**2)**0.5)

    print len([a for a in chords if a > 3**0.5])/float(samp)

Basically make the unit circle at 0,0. Pick any radius up to infinity (infinite plane). By symmetry, we don't need 2 coordinates, just a distance from the circle.

Choose any angle from that point which will draw a vector that intersects the circle (to not waste CPU). Calculate the length of the intersecting chord.

I was really surprised by the distribution of chord lengths, it peaks at chord lengths of 2.0, which is the maximum chord length, and falls exponentially with smaller chord lengths. I don't know what I expected, but not that.

There are no comments on this comment yet.