0

About the title, I've read here that the answer is 11/18.

I've tried with a simple algorithm:

def cut(first_len:int) -> List[Union[float,float]]:
    c1 = random.uniform(0,first_len)
    return [c1, first_len-c1]

if name=='main': max_val = 0

num_iter = 1000000
m_len = 1
for _ in range(num_iter):
    #first random cut
    cut_vals = cut(m_len)

    # second random cut on the longest piece
    max_cut2_vals = cut(max(cut_vals))

    # get the max
    m2 = max(max_cut2_vals)

    max_val = max_val+m2

print(max_val/num_iter)

that returns 0.563, which is a bit lower than 11/18. I assume that I'm missing some fundamental property.

Can someone help me?

Arthur
  • 199,419
mikjkd
  • 3
  • 2
  • Not sure anyone will try to debug your code...the duplicate question speaks for itself. – lulu Mar 25 '24 at 22:46
  • 2
    Why must the second random cut be on the longest piece? The second cut should have a min(cut_vals) probability to be on the shorter piece. – peterwhy Mar 25 '24 at 22:49
  • @peterwhy is correct here. Picking two random cut points is not the same as picking one random cut point and then picking a second cut point on the longer of the two pieces. The latter method favors getting three similar-size pieces more often than it ought. – MJD Mar 25 '24 at 23:23

1 Answers1

2

A rope is divided into three pieces simultaneously: you pick two random real numbers $x, y$ from the $(0, 1)$ interval and then pick the longest piece: either from $0$ to $x$ (which has length $x$), from $x$ to $y$ (which has length $y-x$) or from $y$ to $1$ (which has length $1 - y$). This is assuming that $0 \le x \le y \le 1$ which we can simulate easily in Python:

#!/usr/bin/env python3
from random import random
from statistics import mean

def two_cuts(): x, y = random(), random() if x > y x, y = y, x # to make sure that 0 <= x <= y <= 1 return (x, y)

def longest(x, y): return max(x, 1-y, y-x)

print(mean([longest(two_cuts()) for _ in range(10*5)]))

I've got $0.611285852578838 \approx 0.611111111111111 \ldots = 11/18$. Everything agrees.

  • Yes, you're right. The question is picking the two numbers simultaneously (and not as a choice as I did before).

    Thank you!

    – mikjkd Mar 25 '24 at 23:25