Once, on a sunny spring morning, while reading the city forum, I came across a link with a simple game from a well-known trading network. The game (action), dedicated to the World Cup, was a simple three-by-three field, filled with soccer balls. By clicking on the ball, we opened the picture with one or another product. When opening three identical pictures, the participant was guaranteed to receive this product for free at one of the chain's stores. Also under one of the balls there was an image of a red card, the opening of which meant the end of the game.

Interest in the game quickly faded due to extremely rare cases of winning. Playing the four of us with 6 phone numbers in a few days (about 15 games) no one managed to win. “What is the general probability of winning in this game?” I asked myself and took out a piece of paper, remembering a course in higher mathematics on the move. Writing the formulas, it turned out that each game can contain from 1 to 9 moves, and each move leads to one of three states - winning, losing or continuing the game (except for the first two moves, which can only lead to two states). Quickly realizing that the formula for 9 fields is too complicated, I started with a simple one - 4 fields (three identical products and a red card). A quick sketch of the formulas on a napkin, and it turned out that the probability of winning is 1/4. For 5 fields we had to tinker, but the calculated probability was also 25%. At this moment, I thought and rechecked the calculation three times. That's right. Not to say that I was very surprised, since my studies at the university, I got used to the fact that in the theory of probability the most unexpected results are possible. The calculation for 9 fields would take several sheets of paper and not one hour of time, so a simpler decision was made. Simulate the game script. A few tens of minutes, a cup of coffee, and the script is ready. PowerShell was used as a tool that is always at hand with the system administrator.
$fail = 0
$win = 0
for ($m=1; $m -lt 1001; $m++)
{
$mas = 1, 2, 3, 4, 5, 6, 7, 8, 9
$sum = 0
$result = ""
for ($i=0; $i -lt 8; $i++)
{
$j = Get-Random -Minimum $i -Maximum 9
if ($mas[$j] -eq 9)
{
$result = "FAIL"
break
}
if ($mas[$j] -eq 1 -or $mas[$j] -eq 2 -or $mas[$j] -eq 3) { $sum++ }
if ($sum -eq 3)
{
$result = "WIN"
break
}
$mas[$j] = 0
$mas = $mas | Sort-Object
}
$result
if ($result -eq "WIN") { $win++ }
if ($result -eq "FAIL") { $fail++ }
}
$fail
$win
1, 2 3, 9. , , , , .
, — 25% . , , , , .
. . 10. , .
.
1.3 , , .
! , , .
F12 Chrome, . , . , , , JSON. , “ ” . — , “ ”. , “” . .
JS , 1.5 , , « ». Google JS Beautifier, . , 40 000 . JSON , , — . JSON .

0, 1 2 — , 3 — , .
.

Outcome , JSON, , ! !

! ! , , , . . .
:
8. :
8.1. :
…
166000
, 664000 , , , .
( ).(, ). -. . ()