Blue1Brown绳子概率问题的非AI解法
通过随机选取绳端打结,每轮操作独立且减少一根绳子直至只剩一根。单轮形成环的概率为1 (2S-1),期望环数为所有轮次概率之和,即从50到1的奇数倒数求和。初始50根绳子时,期望环数约为2 94,这是一个统计结果。
Why invest your free time solving a probability puzzle instead of endlessly scrolling through social media? Because it keeps your mind sharp in an era when generative AI handles most of our critical thinking. If you're reading articles on TDS, you and I likely share that objective. (That's one "I" – we'll keep it minimal.)
This article explores a fun probability puzzle recently shared by one of my favorite YouTubers, 3Blue1Brown. Known for his intuitive visuals and explanations that make you wonder why math isn't always taught that way, he presents a perfect exercise in breaking down a problem and discovering elegant solutions.
The problem setup
The short embedded video provides the best introduction, but let's quickly recap the setup. Imagine a box containing multiple strings. You randomly pick one end of a string, then randomly pick another end. You tie those two ends together. Two outcomes are possible: (1) the ends come from different strings, so you now have one longer string; or (2) the second end belongs to the same string you started with, creating a loop.
If you tie two separate strings together, you place the longer string back into the box. If you make a loop, you remove that loop from the box. This process of randomly selecting ends continues until no strings remain. The question: what is the expected number of loops this process produces? More practically, if we repeated this many times, what would the average number of loops be?
Key observations about the problem
Gaining a solid understanding of a problem is always the foundation for a good solution. Beyond the mechanics, a few critical observations set the stage.
Observation #1
Each round involves two random draws: the first and the second. The first draw is almost irrelevant; the second draw determines whether you create a loop or a longer string.
Observation #2
Every round reduces the number of strings in the box by exactly one, regardless of the outcome. If a loop is formed, that string is removed. If a longer string is formed, two strings become one, again reducing the count by one.
Observation #3
The number of draws is not random. Since each round removes one string (from Observation #2) and each round involves two draws, the total number of rounds equals the initial number of strings. If you start with 10 strings, you get 20 draws across 10 rounds. Note that the last round always involves just one remaining string, and that round inevitably creates a loop.
Observation #4
This builds on the previous three and is the most important. From the perspective of counting loops, each round is independent of prior rounds. This means we can break the problem down into individual rounds rather than considering the entire sequence. (If we were interested in something like the expected circumference of a loop, that independence would not hold – string lengths depend on previous rounds. But for loop count, we're in luck.)
With these observations in place, let's dive into solving the problem.
The “brute force” solution
Most problems (including real-world ones) have a brute-force approach – like digging a swimming pool by hand. For this puzzle, you could draw a probability tree and manually compute the expected number of loops. Let's walk through it briefly.
This approach works for small numbers of strings, but it gets clunky fast. In the video, Grant specifically sets 50 strings as the target – a brute-force tree would have 250 leaves. He did that to push viewers toward smarter solutions. So let's see if we can do better.
Divide and conquer solution
By thinking carefully about the process, we realized that each round is independent (Observation #4). This lets us calculate the expected value for a single draw and then combine multiple draws to solve the full problem.
Expected number of loops from a single draw
As noted in Observation #1, the first draw is unimportant – it's all about the second draw. Let's walk through a simple scenario with 4 strings. We pick one end first (any end will do). The second draw can be any of the remaining ends in the box, except the one we already chose.
With 4 strings, there are 8 ends. After picking the first end, 7 ends remain. Exactly one of those 7 (the other end of the same string) will create a loop; the other 6 will not. The image below makes this clearer than words.
So the probability of making a loop is 1/7, and the probability of not making a loop is 6/7. This gives an expected number of loops from that round of 1×1/7 + 0×6/7 = 1/7.
Generalizing: let S be the number of strings. Then there are 2S ends. After picking the first, you can choose from 2S–1 ends, and only one leads to a loop. So the expected loops for a single round is 1/(2S–1).
Combining multiple draws to solve the full problem
Now that we have a formula for a single round, we need to combine rounds. Because each round is independent (Observation #4) and the number of rounds is deterministic (Observation #2), we can simply add the expected loops from each round – as long as we update the number of strings S for each round. This leads to a summation:
Plugging in S = 50 gives about 2.94 loops. Mission accomplished.
The Monte Carlo solution
Because this problem has a closed-form solution, we could stop here. But it's worth discussing how a Monte Carlo simulation could handle it – and more importantly, how that approach shines when the problem gets hairier. Monte Carlo simulations estimate values through repeated random sampling. In our case, we simulate the drawing process many times, count the loops each time, and take the average. As the number of simulations grows, thanks to the law of large numbers, the average converges to the true expected value.
Here's the core simulation loop (full code available at the link):
from monte_carlo_funcs import create_strings, select_ends, tie_ends
# Run the Monte Carlo
list_of_circles = []
num_strings = 50
num_simulations = 10000
if __name__ == "__main__":
for _ in range(0, num_simulations):
# create the simulated starting box of strings
strings = create_strings(num_strings)
# start circle counter for this simulation
circle_counter = 0
# draw from the box until there are no more strings left
while len(strings) > 0:
end_1, end_2, strings = select_ends(strings)
strings, circle_bool = tie_ends(strings, end_1, end_2)
circle_counter += circle_bool
# add the number of circles for this simulation
list_of_circles.append(circle_counter)
print(np.mean(list_of_circles))
When I ran this (results vary slightly each time), I got 2.95 – very close to the true 2.94. That's the beauty and limitation of Monte Carlo: it gives a good estimate, but not exact precision.
Making the problem harder
Now let's see where Monte Carlo really shines. Suppose instead of the expected number of loops, we want the expected average circumference of the loops. That problem is far more complex because it introduces dependencies between rounds. I wasn't able to find a closed-form solution (though one might exist). But when a closed form is out of reach – which happens more often than not in real data science – Monte Carlo saves the day. We could easily modify the code to track string lengths and calculate loop circumferences when loops are created. This reduces a very hard math problem to a fairly simple coding problem.
The takeaway: when a closed-form solution is difficult or impossible, Monte Carlo offers a practical, flexible alternative.
Conclusion
Deeply understanding a problem and thoughtfully crafting a solution has always been a differentiating data science skill – and with our increasing reliance on generative AI, it's becoming even rarer. This puzzle is a fun way to sharpen those skills. While you may never need to calculate expected loops from a box of strings in your professional work (or at least, it's unlikely), you will frequently face situations where the path to a solution isn't obvious. The ability to understand the problem, break it down into smaller components, and develop a tailored solution transfers directly to real data science and analytics work.
你是一名 AI 行业编辑,请围绕下面这条热点输出一份资讯解读:
热点:Blue1Brown绳子概率问题的非AI解法要求:
1. 先用一句话解释这条热点在讲什么
2. 再总结它为什么重要
3. 说明会影响哪些 AI 产品或内容方向
4. 最后给出 3 个适合资讯站使用的标题
游乐网为非赢利性网站,所展示的游戏/软件/文章内容均来自于互联网或第三方用户上传分享,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系youleyoucom@outlook.com。
相关热点OmniParser是微软AI驱动的SaaS工具,基于YOLOv8和BLIP-2,将UI截图与漫画页面解析为结构化数据,支持UI元素检测、漫画面板分析、对话框及人脸识别,适用于自动化测试、漫画翻译等场景。
通义灵码是贯穿开发全流程的智能编码助手,具备代码智能生成、研发智能问答、多编程语言及编辑器支持、代码安全隐私保障四大核心能力,适用于学生、新手及企业开发者等多类人群,提升编码效率。
基于人工智能的自动化道路巡逻和资产数据收集方案,通过车载相机自动采集路面及周边资产数据,识别裂缝、坑槽等病害并建立数字化台账,同时自动删除隐私图像,实现从被动响应向主动预防的转变,降低巡检成本。
阿里旗下通义智文是一款智能阅读工具,支持网页、论文、图书和自由阅读四种场景,帮助用户快速提取核心观点,节省阅读时间,适合学生、研究人员及职场人士高效处理大量文本。
- 日榜
- 周榜
- 月榜
热点快看
