Erratic Systematic Wormhole Mathematics

Chaos has emerged in a 1×1 field; The fabric of space will never be healed.

The limits of light have been replaced: All matter is teleported to a random place!

How far is the average point displaced?

This rule of space should not be disregarded: You might teleport to exactly where you started.

Hint: Don't set your bar low. Use Monte-Carlo .


The answer is 0.52.

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.

5 solutions

MATLAB Code:

        [X,Y]=meshgrid(0:.01:1,0:.01:1);
         for i=1:10000
       P = randperm(prod(size(X)));
        X1 = X(P);Y1=Y(P);
        D = ((X1-X(:)).^2+(Y1-Y(:)).^2).^.5;
         S(i)=mean(D);
         end
         result = mean(S);
Brock Brown
Feb 6, 2015

Python:

1
2
3
4
5
6
7
8
9
from random import random as r
from math import sqrt
def distance(a,b,c,d):
    return sqrt(abs((a-c)**2+(b-d)**2))
total = 0.0
trials = 10000000
for i in xrange(trials):
    total += distance(r(),r(),r(),r())
print "Answer:", total / trials

Sage Code:

1
2
3
4
5
def monte_carlo():
    x1, y1,x2, y2 = random(), random(), random(), random()
    return sqrt((x1-x2)^2 + (y1-y2)^2)
l1 = map(lambda n: monte_carlo(),xrange(1000000))
print sum(l1)/len(l1)

Sage is a cool language, I'm surprised more people don't use it.

Brock Brown - 6 years, 4 months ago
Piotr Idzik
Feb 13, 2020

R code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
distanceL2 <- function(vec_a, vec_b)
{
  return(sqrt(sum((vec_a-vec_b)^2)))
}

getRandomDist <- function()
{
  return(distanceL2(runif(2, 0, 1), runif(2, 0, 1)))
}

distData = replicate(10000000, getRandomDist())
print(mean(distData))

Wang Xingyu
Sep 17, 2020
1
2
3
4
5
import numpy as np 
a = np.random.rand(2,10000000)
b = np.random.rand(2,10000000)
d = np.sqrt(sum((a - b)**2))
print(np.average(d))    # 0.5214153207282254

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...