Building a Better Windows Terminal—Without Overengineering It

图片
At some point, I realized I had somehow made it this far without ever setting up a terminal that was both pleasant to use and pleasant to look at. So I finally fixed that. A terminal is one of those tools developers touch all day, every day. A good setup is not just eye candy—it removes friction from navigation, command history, file search, and everyday Git work. This post walks through the practical Windows 11 setup I ended up with. It is fast, clean, and useful without sending me too far down the dotfiles rabbit hole. My Starting Point If you are also running Windows 11, the following PowerShell snippet will print a quick summary of your hardware: $cs = Get-CimInstance Win32_ComputerSystem $cpu = Get-CimInstance Win32_Processor $os = Get-CimInstance Win32_OperatingSystem $gpu = Get-CimInstance Win32_VideoController $disk = Get-PhysicalDisk @" Model: $($cs.Manufacturer) $($cs.Model) OS: ...

Monty Hall problem

The Monty Hall problem is a fascinating probability puzzle. I remember that when we learned Bayes' theorem in high school, our math textbook devoted an entire page to it. Unfortunately, I never gave that page the attention it deserved. So, until I started preparing this blog post—maybe only a few days ago—I still did not really understand the problem.

The good news is that I finally do. It is a little embarrassing, perhaps, considering that I am a statistics major.

An xkcd comic about the Monty Hall problem

xkcd #1282: Monty Hall

The problem goes like this:

Suppose you are on a game show and are asked to choose one of three doors. Behind one door is a car; behind each of the other two is a goat. You choose a door—say, Door 1. The host, who knows what is behind every door, then opens one of the other doors—say, Door 3—and reveals a goat. He asks, “Would you like to switch to Door 2?” Is switching to your advantage?

The standard version of the problem assumes that the host always opens a door hiding a goat, never opens the door you selected, and always offers you the chance to switch.

Most people would probably choose to stay. Intuitively, it feels as though the two remaining doors should each have a probability of $\frac{1}{2}$. But if you have studied Bayes' theorem, you may suspect that the situation is not quite that simple.

There are only two possibilities for our initial choice: we have selected either a goat or the car.

The initial choice is a goat The initial choice is the car

At the beginning of the game, the probability that the car is behind any particular door is $\frac{1}{3}$. We can therefore break the problem into three equally likely cases.

Case 1

Suppose our initial choice is a goat. This particular case occurs with probability $\frac{1}{3}$.

Because the host knows where the car is, he must open the other door that hides a goat. The only unopened door left is therefore the one hiding the car.

  • If we switch, we move from a goat to the car and win.
  • If we stay, we remain with the goat and lose.
Case 1 of the Monty Hall problem

Case 2

Suppose our initial choice is the door hiding the car. This case also occurs with probability $\frac{1}{3}$.

Because the host knows what is behind every door, he must open one of the two remaining doors, both of which hide goats. The only other unopened door will therefore also hide a goat.

  • If we switch, we move from the car to a goat and lose.
  • If we stay, we keep the car and win.
Case 2 of the Monty Hall problem

Case 3

The third case is essentially the same as the first: our initial choice is the other goat. Once again, switching leads us to the car.

Case 3 of the Monty Hall problem

The problem has now become a simple exercise in classical probability. Switching wins in two of the three equally likely cases:

$$ P(\text{win by switching}) = \frac{1}{3} + \frac{1}{3} = \frac{2}{3}. $$

By contrast, staying wins in only one case:

$$ P(\text{win by staying}) = \frac{1}{3}. $$

A More Mathematical Approach

We can also analyze the problem using Bayes' theorem.

Suppose we initially choose Door 1 and the host opens Door 3. Define the events

$$ C_i=\{\text{the car is behind Door }i\}, \qquad i\in\{1,2,3\}, $$

and

$$ H_3=\{\text{the host opens Door 3}\}. $$

Before the host opens a door, each possible location of the car has probability $\frac{1}{3}$:

$$ P(C_1)=P(C_2)=P(C_3)=\frac{1}{3}. $$

We also assume that if the car is behind Door 1, the host chooses randomly between Doors 2 and 3, since both hide goats. Therefore,

$$ P(H_3\mid C_1)=\frac{1}{2}. $$

If the car is behind Door 2, the host must open Door 3:

$$ P(H_3\mid C_2)=1. $$

If the car is behind Door 3, the host cannot open Door 3:

$$ P(H_3\mid C_3)=0. $$

Using the law of total probability, we obtain

$$ \begin{aligned} P(H_3) &=P(H_3\mid C_1)P(C_1) +P(H_3\mid C_2)P(C_2) +P(H_3\mid C_3)P(C_3)\\ &=\frac{1}{2}\times\frac{1}{3} +1\times\frac{1}{3} +0\times\frac{1}{3}\\ &=\frac{1}{2}. \end{aligned} $$

Bayes' theorem now gives the probability that our original choice, Door 1, hides the car:

$$ \begin{aligned} P(C_1\mid H_3) &=\frac{P(H_3\mid C_1)P(C_1)}{P(H_3)}\\ &=\frac{\frac{1}{2}\times\frac{1}{3}}{\frac{1}{2}}\\ &=\frac{1}{3}. \end{aligned} $$

Meanwhile, the probability that the car is behind Door 2—the door we can switch to—is

$$ \begin{aligned} P(C_2\mid H_3) &=\frac{P(H_3\mid C_2)P(C_2)}{P(H_3)}\\ &=\frac{1\times\frac{1}{3}}{\frac{1}{2}}\\ &=\frac{2}{3}. \end{aligned} $$

Therefore,

$$ P(\text{win by switching})=\frac{2}{3}, $$

while

$$ P(\text{win by staying})=\frac{1}{3}. $$

If you have made it this far, I hope you now have a solid understanding of the problem. Probability theory is full of fascinating—and often rather tricky—questions like this one.

It is worth noting that even Paul Erdős, one of the most prolific mathematicians in history, was reportedly skeptical of the switching strategy until he saw the results of a computer simulation.1

So there is nothing unusual about finding the problem confusing at first. In fact, one of the deepest lessons I have learned from mathematics—and especially from probability theory—is just how unreliable intuition can be. 😓


1 Vazsonyi, Andrew (December 1998–January 1999). ↩

评论

此博客中的热门博文

How Google Ranks the Web

Building a Better Windows Terminal—Without Overengineering It