static_steps = 1e7 # number of times we trow the stick L = 10 # length of the table l = 0.8 # length of the stick d = 1 # distance between lines result = 2*l/(pi*d) # expected theoretical result x = random(0, L) # location of the center of the stick theta = random(0, 2*pi) # the resulting angle x1 = x + 0.5*l*cos(theta) # coordinates of the stick ends x2 = x - 0.5*l*cos(theta) # increase count if the stick crosses one line # (remember ! is the "not equal" operator) count = count + (floor(x1/d)!floor(x2/d)) # print the partial results PRINT %g step_static count/step_static result SKIP_STATIC_STEP 1e5