Magnet

Chris has a 2 × 2 2\times2 square board. He wants to perform a Monte-Carlo simulation to find out the average distance between two points by randomly throwing two metal beads on the board and measure their distance. However, his brother Patrick secretly hid a magnet below one of the quadrants such that 70% of the metal beads will land uniformly on that area, and 30% of the metal beds will land uniformly in the other quadrants.

Chris is very confused as the answer doesn't match the one in his computation. Instead, what is the answer Chris found?

Give your answer to 4 decimal places.


The answer is 0.8596.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Christopher Boo
Jun 16, 2016

The percentage of landing on the first quadrant is 70 % 70\% , and 10 % 10\% for all second, third and forth quarter.

Using the probability distribution above your code might looks complicated. Instead, it can be transformed as :

The percentage of landing on the first quadrant is 60 % 60\% , and 40 % 40\% will evenly land on any point on the board.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import math
from random import randint

def dist(x1,y1,x2,y2):
    return math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))

tst = 0
ans = 0
while True:

    # first point
    case = randint(1,10)     # 1 <= case <= 10
    if case <= 6:            # first quadrant
        x1 = randint(0,100) / 100.0
        y1 = randint(0,100) / 100.0
    else:                    # full board
        x1 = randint(0,200) / 100.0
        y1 = randint(0,200) / 100.0

    # second point
    case = randint(1,10)
    if case <= 6:
        x2 = randint(0,100) / 100.0
        y2 = randint(0,100) / 100.0
    else:
        x2 = randint(0,200) / 100.0
        y2 = randint(0,200) / 100.0

    d = dist(x1,y1,x2,y2)

    tst += 1
    ans += d

    print tst, ans / tst

Relevant wiki: Monte-Carlo Simulation

Python 3.5.1:

import random
from math import sqrt

def generatepoint():
    seed = random.randint(1,100)
    quadrant = None
    if 1<=seed<=70:
        quadrant = 1
    elif 71<=seed<=80:
        quadrant = 2
    elif 81<=seed<90:
        quadrant = 3
    else:
        quadrant = 4

    x=random.randint(0,100)
    y=random.randint(0,100)
    if quadrant==1:
        pass
    elif quadrant==2:
        y=-y
    elif quadrant==3:
        x=-x
        y=-y
    else:
        x=-x
    return (x,y)

def distance(point1,point2):
    return sqrt((point1[0]-point2[0])**2+(point1[1]-point2[1])**2)

ave = 0
for i in range(0,100000):
    a=generatepoint()
    b=generatepoint()
    ave+=distance(a,b)
print (ave/100000)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...