This time I want to show how to solve a game using a perfect play which means being able to predict the outcome of the game from any position. The perfect play is the strategy that leads to the best possible outcome for that player regardless of the response by the opponent.
For the illustration I have selected two children’s games with stones. The rules are very simple. There is a pile of 99 stones. Two player take n stones out of the pile in turn. The one who takes the last stone is the winner. In each game n is different:

  1. it is in the closed interval between 1 and 3
  2. power of 2

Let’s find out how to always win these games. Continue reading Finding winning strategies

Read more

Storing data in MongoDB with the official C# driver sooner or later you might run into the following

This is happening because of the limitation of a single document size that exists in MongoDB by design.

The maximum BSON document size is 16 megabytes.

The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth.

Though there is a JIRA ticket called Increase max document size to at least 64mb, it doesn’t seem likely to be done in the near future. Geert Bosch, senior software engineer at MongoDB, wrote the
following comment:

In order to support much larger documents, such as the 64Mb documents suggested, assumptions such as that we can easily allocate copies of documents for modification will no longer hold. Transactions could grow extremely large (just think of a 64Mb array of elements to index). We would need to significantly throttle the number of concurrent operations, or raise the memory requirements for mongod.

But, if you find yourself stuck in such a situation, don’t get frustrated – there is a solution. Continue reading Reducing the size of MongoDB document in c#

Read more