# 6 games in 6 weeks - the third game

There should be seals on Friday. I have them.

Game Three - B4 .

This is real solitaire. Complex as a request in Perl.

Because success will be enjoyed only by mathematicians from Habr and travel on the train Moscow-Yekaterinburg.

In my report, I will briefly (lines 40) tell about the generation of layouts, put forward a lemma on the convergence of any layout that has two degrees of freedom and demonstrate how I was a boot and became a grandfather.

To the comments, zikher proposed a counter-example that seems to refute the lemma. But they decided an example.

The rules are the same as in the game Four rooms . There is colored rubbish in the room. Trash can be driven around the room with finger movements across the screen — either horizontally or vertically.

Red trash can be thrown through the red wall. Yellow trash through yellow. Blue- through blue. Blue - blue. There are no more rules.

Understood? Let's move on to the examples.

Look at Figure 1. It is necessary to clean the room of colored debris.

Figure 1. The simplest layout

The solution for the layout in Figure 1 consists of two moves.

Solitaire resolved.

In Figure 2, the example is more complicated.

Figure 2. If you make the first move up, solitaire will not converge.

The layout solution in Figure 2 consists of five moves.

Solitaire resolved.

In solitaire, the generation of hands is very important. On the one hand, they should be random, on the other hand, it should always be possible to repeat a random alignment - either throw it to a friend weakly !, or play it again yourself.

The problem is that my game is universal - there is a game for the iPhone, but there is an Internet option. How to achieve the same layout on Objective-C and JavaScipt?

Oddly enough - the solution lies in Visual Studio from Microsoft.

I climbed into the math of the VS library and pulled out the code for the pseudo-random number generation function.

By setting the initial value in the global

In JavaScript, this function looks a little different.

It was experimentally verified that the result of the function in all systems is identical.

Thus setting the

The first time I started the game, I was upset. The alignment chosen by me did not converge. I wound up. That is, I got a big picture with a pretty aunt, closed it with buttons from the first 256 layouts and started playing wisely. With the correct decision of the next scenario, the button disappeared and the aunt was exposed.

As a result, on the third day, I decided 255 out of 256 hands. I could not solve only one - in which initially there was no horizontal movement.

From here a lemma was born, which I could not prove - if there are two degrees of freedom, any complete solitaire is going on board 5 on 5 and above.

Thank you for your attention, the animation of the seals dancing Nanai boys - exclusively to the wise men who formed the solitaire.

Game Three - B4 .

This is real solitaire. Complex as a request in Perl.

Because success will be enjoyed only by mathematicians from Habr and travel on the train Moscow-Yekaterinburg.

In my report, I will briefly (lines 40) tell about the generation of layouts, put forward a lemma on the convergence of any layout that has two degrees of freedom and demonstrate how I was a boot and became a grandfather.

To the comments, zikher proposed a counter-example that seems to refute the lemma. But they decided an example.

#### rules

The rules are the same as in the game Four rooms . There is colored rubbish in the room. Trash can be driven around the room with finger movements across the screen — either horizontally or vertically.

Red trash can be thrown through the red wall. Yellow trash through yellow. Blue- through blue. Blue - blue. There are no more rules.

Understood? Let's move on to the examples.

Look at Figure 1. It is necessary to clean the room of colored debris.

Figure 1. The simplest layout

The solution for the layout in Figure 1 consists of two moves.

- move chips to the right (red trash disappears through the red wall)
- move chips up (blue trash disappears)

Solitaire resolved.

In Figure 2, the example is more complicated.

Figure 2. If you make the first move up, solitaire will not converge.

The layout solution in Figure 2 consists of five moves.

- move chips to the right
- move chips down
- move chips to the left (yellow trash will disappear)
- move chips up (blue trash disappears)
- move chips to the right

Solitaire resolved.

#### Example number 66

#### Layout Generation

In solitaire, the generation of hands is very important. On the one hand, they should be random, on the other hand, it should always be possible to repeat a random alignment - either throw it to a friend weakly !, or play it again yourself.

The problem is that my game is universal - there is a game for the iPhone, but there is an Internet option. How to achieve the same layout on Objective-C and JavaScipt?

Oddly enough - the solution lies in Visual Studio from Microsoft.

I climbed into the math of the VS library and pulled out the code for the pseudo-random number generation function.

```
- (int)microsoft_rnd {
holdrand = holdrand * 214013 + 2531011;
return ((holdrand >> 16) & 0x7FFF);
}
```

By setting the initial value in the global

*holdrand*variable , I can repeat the random sequence as many times as I want. For convenience, I started 1,000,000 initial handouts and expanded the functionality of my class.```
- (int) microsoft_rand:(int) number{
return [self microsoft_rnd] % number;
}
// Пример использования функции - получение случайного числа в диапазоне 1 - 4
...
int k = 1 + [self microsoft_rand:4];
...
```

In JavaScript, this function looks a little different.

```
function microsoft_rnd()
{
var r;
var big = 4294967295+1;
microsoft_rnd.seed = (microsoft_rnd.seed * 214013 + 2531011)%big;
r = microsoft_rnd.seed;
r = Math.floor(r/65536);
r = r%32768;
return r;
}
function microsoft_rand(number)
{
return (microsoft_rnd())%number;
};
```

It was experimentally verified that the result of the function in all systems is identical.

Thus setting the

*holdrand*equal to, for example, 2015, I get the same layout on both the iPhone and the browser.#### How I tested the game

The first time I started the game, I was upset. The alignment chosen by me did not converge. I wound up. That is, I got a big picture with a pretty aunt, closed it with buttons from the first 256 layouts and started playing wisely. With the correct decision of the next scenario, the button disappeared and the aunt was exposed.

As a result, on the third day, I decided 255 out of 256 hands. I could not solve only one - in which initially there was no horizontal movement.

From here a lemma was born, which I could not prove - if there are two degrees of freedom, any complete solitaire is going on board 5 on 5 and above.

#### Have a nice weekend

Thank you for your attention, the animation of the seals dancing Nanai boys - exclusively to the wise men who formed the solitaire.